“基于Docker的Jenkins持续集成”的版本间的差异
(→ins) |
|||
(未显示同一用户的69个中间版本) | |||
第1行: | 第1行: | ||
− | = | + | =站内资源see also= |
+ | [[触发器之jenkins实现gitlab trigger]] | ||
− | 站内资源[[Jenkins迁移之备份和还原]] | + | [[Jenkins自动化构建和部署例子]] |
+ | |||
+ | =install= | ||
+ | |||
+ | gitlab→jenkins→registry→kubernetes→docker | ||
+ | |||
+ | 站内资源 | ||
+ | |||
+ | [[Jenkins进行持续集成]] 相关配置的看这个吧 | ||
+ | |||
+ | [[Jenkins实现PHP持续集成部署]] | ||
+ | |||
+ | [[Jenkins迁移之备份和还原]] | ||
+ | |||
+ | [[Jenkins自动化构建和部署例子]] | ||
+ | |||
+ | |||
+ | NOTE 注意 国内环境安装完 记得 Jenkins安装插件提速 在后面章节哦 | ||
+ | |||
+ | https://github.com/jenkinsci/docker/blob/587b2856cd225bb152c4abeeaaa24934c75aa460/Dockerfile | ||
<pre> | <pre> | ||
+ | /data/apps/jenkins | ||
− | |||
− | |||
mkdir docker4jenkins | mkdir docker4jenkins | ||
cd docker4jenkins | cd docker4jenkins | ||
第16行: | 第35行: | ||
services: | services: | ||
jenkins: | jenkins: | ||
− | + | image: evan886/jenkins2021:v1 | |
− | image: jenkins/jenkins:2.235.5-lts-alpine | + | image: jenkins/jenkins:2.303.3-lts-alpine |
+ | image: jenkins/jenkins:lts #如果构建环境比较多样 还是建议用官方的debian | ||
+ | #image: jenkins/jenkins:2.235.5-lts-alpine | ||
+ | #image: jenkins/jenkins:2.190.3-alpine #202011 迁移用的版本 可以跑phing2.16 | ||
ports: | ports: | ||
- 7099:8080/tcp | - 7099:8080/tcp | ||
第35行: | 第57行: | ||
#run | #run | ||
docker-compose up -d jenkins | docker-compose up -d jenkins | ||
+ | |||
+ | </pre> | ||
+ | == install config== | ||
+ | <pre> | ||
+ | 注意 : | ||
+ | 打开 url 时行 | ||
+ | 注意 如果在初始化时用了自定义的名,就不要选择下面第一个 有admin字样的选项了 continue as admin ,而 选择Save and Finish | ||
+ | |||
+ | 可能要改的变量 这里我加了2021 还有暴露给母鸡的端口也可能要改 如果一台机器有多个 jenkins | ||
+ | restart: always | ||
+ | volumes: | ||
+ | #- /data/jenkins:/var/jenkins_home:rw | ||
+ | - jenkins_home2021:/var/jenkins_home:rw | ||
+ | version: '3.0' | ||
+ | volumes: | ||
+ | jenkins_home2021: | ||
+ | driver: local | ||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
第54行: | 第98行: | ||
cat initialAdminPassword | cat initialAdminPassword | ||
05765dd93d604cd094b516ba9cc06c1a | 05765dd93d604cd094b516ba9cc06c1a | ||
+ | |||
+ | ng | ||
+ | |||
+ | cat ci.conf | ||
+ | server { | ||
+ | listen 80; | ||
+ | server_name market-ci.com; | ||
+ | |||
+ | |||
+ | location / { | ||
+ | proxy_pass http://172.31.127.223:7099; | ||
+ | proxy_set_header X-Real-IP $remote_addr; | ||
+ | proxy_set_header Host $host; | ||
+ | proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; | ||
+ | |||
+ | } | ||
+ | } | ||
+ | |||
+ | |||
重装要删除volumes 然后要重启 docker | 重装要删除volumes 然后要重启 docker | ||
第92行: | 第155行: | ||
</pre> | </pre> | ||
+ | =alpine jenkins= | ||
+ | [https://blog.csdn.net/liumiaocn/article/details/86098125 Jenkins实践基础:Alpine版Jenkins(LTS版)] | ||
= 常用命令= | = 常用命令= | ||
重启 | 重启 | ||
http://localhost:8080/restart http://localhost:8080/reload | http://localhost:8080/restart http://localhost:8080/reload | ||
+ | |||
+ | =常用参数= | ||
+ | <pre> | ||
+ | |||
+ | Transfers set | ||
+ | |||
+ | Remote directory | ||
+ | 填写 tempjar 如果是用root用户 那就是 /root/tempjar/ | ||
+ | |||
+ | 有些项目改了 绝对路径居然是不行的 | ||
+ | |||
+ | |||
+ | </pre> | ||
+ | |||
=install plugins= | =install plugins= | ||
+ | == change repositories== | ||
+ | <pre> | ||
+ | echo 'http://mirrors.aliyun.com/alpine/v3.14/main | ||
+ | http://mirrors.aliyun.com/alpine/v3.14/community' >/etc/apk/repositories | ||
+ | |||
+ | </pre> | ||
==maven== | ==maven== | ||
第152行: | 第237行: | ||
==dokcer 插件 == | ==dokcer 插件 == | ||
为了发布 docker | 为了发布 docker | ||
+ | == git 用户 == | ||
+ | <pre> | ||
+ | 系统-->凭证 | ||
+ | Enter directly ->Key 添加 pri key | ||
+ | |||
+ | |||
+ | 要在 Key 框里添加你的 pri key 不然会出这报错 | ||
+ | Failed to connect to repository : Command "git ls-remote -h ssh://[email protected]:2222/lxtx-cailu-java-projects/lxtx-cailu-market.git HEAD" returned status code 128: | ||
+ | stdout: | ||
+ | stderr: Permission denied (publickey). | ||
+ | fatal: Could not read from remote repository. | ||
+ | |||
+ | Please make sure you have the correct access rights | ||
+ | and the repository exists. | ||
+ | |||
+ | |||
+ | 行情改成这样的 git | ||
+ | |||
+ | ssh://[email protected]:2222/lxtx-cailu-java-projects/lxtx-cailu-market.git | ||
+ | |||
+ | </pre> | ||
+ | |||
+ | == 数据库更新 == | ||
+ | liquibase | ||
+ | |||
+ | |||
+ | [https://www.jianshu.com/p/bc25097996b6 使用 LiquiBase 管理数据库变更 数据库版本管理(含与Spring Boot Gradle Liquibase 插件整合的demo)] | ||
+ | |||
+ | [https://blog.csdn.net/zuokaopuqingnian/article/details/78902987 LiquiBase 进行数据库持续更新] | ||
+ | |||
+ | |||
+ | == npm yarn== | ||
+ | <pre> | ||
+ | |||
+ | #on contain | ||
+ | apk add --update nodejs npm | ||
+ | apk add --update yarn | ||
+ | |||
+ | #web界面也要加上 相关的plugins | ||
+ | nodejs npm yarn | ||
+ | |||
+ | |||
+ | 改源 最好写文件 | ||
+ | |||
+ | npm config set registry https://registry.nlark.com/ | ||
+ | npm config set electron_mirror https://npm.taobao.org/mirrors/electron/ | ||
+ | yarn config set sass_binary_site https://npm.taobao.org/mirrors/node-sass/ | ||
+ | </pre> | ||
+ | |||
+ | ==golang== | ||
+ | <pre> | ||
+ | |||
+ | |||
+ | #install package | ||
+ | apk add --no-cache git make musl-dev go rsync | ||
+ | |||
+ | |||
+ | # 进入项目代码所在目录 | ||
+ | cd ${WORKSPACE}/www | ||
+ | |||
+ | # GO编译项目代码成可执行文件 | ||
+ | #/usr/local/go/bin/go build -o chat-auto-service . | ||
+ | |||
+ | go build -o chat-auto-service . | ||
+ | |||
+ | # 同步可执行文件到正式环境 | ||
+ | env RSYNC_PASSWORD=pass rsync -az --port=873 $WORKSPACE/www/chat-auto [email protected]::lc-chat-auto-service | ||
+ | |||
+ | </pre> | ||
+ | |||
+ | ==php == | ||
+ | 可见有多个版本的 php | ||
+ | https://wiki.alpinelinux.org/wiki/Nginx_with_PHP | ||
+ | <pre> | ||
+ | |||
+ | apk add php composer | ||
+ | apk add php7-fpm php7-mcrypt php7-soap php7-openssl php7-gmp php7-pdo_odbc php7-json php7-dom php7-pdo php7-zip php7-mysqli php7-sqlite3 php7-apcu php7-pdo_pgsql php7-bcmath php7-gd php7-odbc php7-pdo_mysql php7-pdo_sqlite php7-gettext php7-xmlreader php7-xmlrpc php7-bz2 php7-iconv php7-pdo_dblib php7-curl php7-ctype | ||
+ | |||
+ | php7 -v | ||
+ | apk add php5-fpm php5-mcrypt php5-soap php5-openssl php5-gmp php5-pdo_odbc php5-json php5-dom php5-pdo php5-zip php5-mysql php5-mysqli php5-sqlite3 php5-apcu php5-pdo_pgsql php5-bcmath php5-gd php5-xcache php5-odbc php5-pdo_mysql php5-pdo_sqlite php5-gettext php5-xmlreader php5-xmlrpc php5-bz2 php5-memcache php5-mssql php5-iconv php5-pdo_dblib php5-curl php5-ctype | ||
+ | |||
+ | |||
+ | #ss lc项目打包要用到 | ||
+ | apk add php composer | ||
+ | |||
+ | apk add php7-redis php7-xmlwriter php7-simplexml php7-sockets php7-tokenizer | ||
+ | |||
+ | |||
+ | |||
+ | |||
+ | 大不了 php5.6源码嘛 | ||
+ | </pre> | ||
+ | |||
+ | ==python plugin== | ||
+ | apk add python2 | ||
+ | Jenkins 执行python脚本 安装如下两个 plugin | ||
+ | |||
+ | python_plugin python_wrapper_plugin | ||
+ | |||
+ | 任务中添加python脚本即可,点击保存时候,自动会在下图中目录生成.py文件 | ||
+ | [https://cloud.tencent.com/developer/article/1566505 jenkins执行python脚本的方法] | ||
=生成SSHKey= | =生成SSHKey= | ||
第180行: | 第366行: | ||
https://wiki.jenkins.io/display/JENKINS/Change+time+zone | https://wiki.jenkins.io/display/JENKINS/Change+time+zone | ||
+ | |||
+ | =nginx config Reverse proxy - Nginx= | ||
+ | |||
+ | [https://www.jenkins.io/doc/book/system-administration/reverse-proxy-configuration-nginx/ Reverse proxy - Nginx] | ||
=trouble = | =trouble = | ||
第185行: | 第375行: | ||
第二天不能登录 这个是输入错了吧 | 第二天不能登录 这个是输入错了吧 | ||
Invalid username or password | Invalid username or password | ||
+ | == 迁移 jenkins 要注意的== | ||
+ | <pre> | ||
+ | java.io.IOException: Cannot run program "/var/jenkins_home/tools/hudson.model.JDK/jdk/bin/java" (in directory "/var/jenkins_home/workspace/pro-cailu-market"): error=2, No such file or directory | ||
+ | maven | ||
+ | 要重新 配置 全局-->maven 安装 | ||
− | ==Jenkins安装插件提速== | + | |
+ | hudson.AbortException: Unable to install JDK unless a valid username/password is provided. | ||
+ | |||
+ | 填写 oracle用户和密码 原来 用户 密码是oracle提供的 | ||
+ | |||
+ | http://market-ci.com/descriptorByName/hudson.tools.JDKInstaller/enterCredential | ||
+ | |||
+ | 要重新添加 git 用户 和密码 | ||
+ | |||
+ | |||
+ | |||
+ | Remote directory | ||
+ | 填写 tempjar 如果是用root用户 那就是 /root/tempjar/ | ||
+ | |||
+ | </pre> | ||
+ | |||
+ | ==Jenkins安装插件提速 插件换源== | ||
+ | |||
+ | [https://www.oschina.net/news/111266/jenkins-plugin-mirror Jenkins 插件中心国内镜像源发布] | ||
<pre> | <pre> | ||
+ | |||
+ | 现在感觉不改更快 | ||
docker-compose exec --user root jenkins bash | docker-compose exec --user root jenkins bash | ||
+ | find / -name default.json #如果是原生的安装 | ||
cd /var/jenkins_home/updates | cd /var/jenkins_home/updates | ||
+ | #还是用 ! 不然#的可能在alpine不生效 | ||
+ | sed -i 's!https://updates.jenkins.io/download!https://mirrors.tuna.tsinghua.edu.cn/jenkins!g' default.json | ||
+ | sed -i 's!http://updates.jenkins-ci.org/download!https://mirrors.tuna.tsinghua.edu.cn/jenkins!g' default.json | ||
+ | sed -i 's!http://www.google.com!https://www.baidu.com!g' default.json | ||
+ | |||
+ | # #号的放弃了 Friday May six 2022 | ||
sed -i 's#https://updates.jenkins.io/download#https://mirrors.tuna.tsinghua.edu.cn/jenkins#g' default.json | sed -i 's#https://updates.jenkins.io/download#https://mirrors.tuna.tsinghua.edu.cn/jenkins#g' default.json | ||
− | |||
sed -i 's#http://updates.jenkins-ci.org/download#https://mirrors.tuna.tsinghua.edu.cn/jenkins#g' default.json | sed -i 's#http://updates.jenkins-ci.org/download#https://mirrors.tuna.tsinghua.edu.cn/jenkins#g' default.json | ||
sed -i 's#http://www.google.com#https://www.baidu.com#g' default.json | sed -i 's#http://www.google.com#https://www.baidu.com#g' default.json | ||
+ | |||
+ | 重启生效 docker-compose restart jenkins | ||
+ | #不用下面这个吧 | ||
http://192.168.10.54:7099/restart | http://192.168.10.54:7099/restart | ||
− | + | web界面在线修改 插件镜像 | |
+ | 安装插件可能失败,大概率是因为网络原因,所以这里修改一下插件的安装镜像地址。 | ||
+ | |||
+ | 打开 系统管理->插件管理->高级->升级站点,改成清华大学的镜像地址 | ||
+ | |||
+ | https://mirrors.tuna.tsinghua.edu.cn/jenkins/updates/update-center.json | ||
+ | |||
+ | 或者直接在母机 | ||
+ | /var/lib/docker/volumes/jenkins_jenkins_home/_data/updates | ||
+ | |||
+ | |||
</pre> | </pre> | ||
https://blog.csdn.net/weixin_43557605/article/details/104587304 | https://blog.csdn.net/weixin_43557605/article/details/104587304 | ||
+ | |||
+ | ==docker-compose 相关文件被删除== | ||
+ | 处理办法 数据目录(我用了默认的)没被 删除 ,再搞个 docker-compose.yml 文件就行了 和对应目录 | ||
==Jenkins忘记密码 == | ==Jenkins忘记密码 == | ||
<pre> | <pre> | ||
+ | |||
+ | #2021 试过有效果 | ||
+ | /var/jenkins_home/users/admin/config.xml | ||
+ | |||
+ | 新版本 | ||
+ | jenkins_jenkins_home/_data/users/admin_1216381497456990300 | ||
+ | |||
+ | cat config.xml | grep passwordHash | ||
+ | <passwordHash>#jbcrypt:$2a$10$MiIVR0rr/UhQBqT.bBq0QehTiQVqgNpUGyWW2nJObaVAM/2xSQdSq</passwordHash> | ||
+ | |||
+ | |||
+ | 123456加密后: #jbcrypt:$2a$10$MiIVR0rr/UhQBqT.bBq0QehTiQVqgNpUGyWW2nJObaVAM/2xSQdSq | ||
+ | |||
+ | 修改 /users/admin/comfig.xml 文件后,保存重新启动Jenkins程序。 | ||
+ | |||
+ | 再以用户名admin 密码123456 成功登录 | ||
#note 这是基于docker的jenkins | #note 这是基于docker的jenkins | ||
第224行: | 第477行: | ||
+ | #jbcrypt:$2a$10$MiIVR0rr/UhQBqT.bBq0QehTiQVqgNpUGyWW2nJObaVAM/2xSQdSq | ||
+ | 123456 | ||
+ | |||
+ | 这个写法有问题啦 前面不是固定的啦 | ||
sed -i 's!#jbcrypt:$2a$10$h/LCaTsmNht3F04LbZPsY.OtTyx1e/P7pit6Te7KjGVXkhe/caqyW!#jbcrypt:$2a$10$DdaWzN64JgUtLdvxWIflcuQu2fgrrMSAMabF5TSrGK5nXitqK9ZMS!' config.xml | sed -i 's!#jbcrypt:$2a$10$h/LCaTsmNht3F04LbZPsY.OtTyx1e/P7pit6Te7KjGVXkhe/caqyW!#jbcrypt:$2a$10$DdaWzN64JgUtLdvxWIflcuQu2fgrrMSAMabF5TSrGK5nXitqK9ZMS!' config.xml | ||
− | 后者是111111的hash值 | + | 后者是111111的hash值 6个1 |
docker-compose restart | docker-compose restart | ||
第232行: | 第489行: | ||
</pre> | </pre> | ||
+ | |||
+ | [https://blog.csdn.net/qq_40907977/article/details/109549811?utm_medium=distribute.pc_relevant.none-task-blog-title-15&spm=1001.2101.3001.4242 这个有用 jenkins 忘记密码或认证配置出错后解决办法] | ||
[https://www.jianshu.com/p/e8bc90a1aad8 Jenkins - Jenkins 忘记密码] | [https://www.jianshu.com/p/e8bc90a1aad8 Jenkins - Jenkins 忘记密码] | ||
第276行: | 第535行: | ||
https://www.jianshu.com/p/1e411d225186 | https://www.jianshu.com/p/1e411d225186 | ||
+ | ===web打不开 wrapper Up (unhealthy) === | ||
+ | <pre> | ||
+ | 重启并等 一下下 过程如下 | ||
+ | docker-compose ps | ||
+ | Name Command State Ports | ||
+ | ------------------------------------------------------------------------------------------------------------------- | ||
+ | gitlab_web_1 /assets/wrapper Up (unhealthy) 0.0.0.0:2222->22/tcp, 0.0.0.0:4433->443/tcp, 0.0.0.0:7080->80/tcp | ||
+ | root@jenkins2020:/data/apps/gitlab# docker-compose restart | ||
+ | Restarting gitlab_web_1 ... done | ||
+ | root@jenkins2020:/data/apps/gitlab# docker-compose ps | ||
+ | Name Command State Ports | ||
+ | -------------------------------------------------------------------------------------------------------------------------- | ||
+ | gitlab_web_1 /assets/wrapper Up (health: starting) 0.0.0.0:2222->22/tc | ||
+ | |||
+ | docker-compose ps | ||
+ | Name Command State Ports | ||
+ | ----------------------------------------------------------------------------------------------------------------- | ||
+ | gitlab_web_1 /assets/wrapper Up (healthy) 0.0.0.0:2222->22/tcp, 0.0.0.0:4433->443/tcp, 0.0.0.0:7080->80/tcp | ||
+ | root@jenkins2020:/data/apps/gitlab# | ||
+ | |||
+ | |||
+ | </pre> | ||
+ | |||
+ | ===删除home数据目录=== | ||
+ | mkdir -p /var/lib/docker/volumes/jenkins_jenkins_home/_data #可能要创建回去 | ||
− | = | + | =re= |
https://hub.docker.com/r/jenkins/jenkins | https://hub.docker.com/r/jenkins/jenkins | ||
第293行: | 第577行: | ||
[https://dev.to/andresfmoya/install-jenkins-using-docker-compose-4cab Install Jenkins using Docker Compose] | [https://dev.to/andresfmoya/install-jenkins-using-docker-compose-4cab Install Jenkins using Docker Compose] | ||
+ | |||
+ | |||
+ | [https://www.codenong.com/cs110260624/ jenkins自动化部署+git安装配置(多秘钥)+maven安装配置] | ||
==learn== | ==learn== | ||
[https://www.cnblogs.com/dzblog/category/945869.html Jenkins学习之路] | [https://www.cnblogs.com/dzblog/category/945869.html Jenkins学习之路] | ||
− | [[category:ops]] | + | |
+ | [https://jenkins-zh.cn/ Jenkins 中文社区 ] | ||
+ | |||
+ | [https://zhuanlan.zhihu.com/p/266883329 Docker结合jenkins完成快捷打包部署] | ||
+ | [[category:ops]] [[category:devops]] [[category:jenkins]] |
2022年5月6日 (五) 07:17的最新版本
目录
站内资源see also
install
gitlab→jenkins→registry→kubernetes→docker
站内资源
Jenkins进行持续集成 相关配置的看这个吧
NOTE 注意 国内环境安装完 记得 Jenkins安装插件提速 在后面章节哦
https://github.com/jenkinsci/docker/blob/587b2856cd225bb152c4abeeaaa24934c75aa460/Dockerfile
/data/apps/jenkins mkdir docker4jenkins cd docker4jenkins #mkdir -p /data/jenkins vi docker-compose.yml services: jenkins: image: evan886/jenkins2021:v1 image: jenkins/jenkins:2.303.3-lts-alpine image: jenkins/jenkins:lts #如果构建环境比较多样 还是建议用官方的debian #image: jenkins/jenkins:2.235.5-lts-alpine #image: jenkins/jenkins:2.190.3-alpine #202011 迁移用的版本 可以跑phing2.16 ports: - 7099:8080/tcp - 50000:50000/tcp environment: TZ: Asia/Shanghai restart: always volumes: #- /data/jenkins:/var/jenkins_home:rw - jenkins_home:/var/jenkins_home:rw version: '3.0' volumes: jenkins_home: driver: local #run docker-compose up -d jenkins
install config
注意 : 打开 url 时行 注意 如果在初始化时用了自定义的名,就不要选择下面第一个 有admin字样的选项了 continue as admin ,而 选择Save and Finish 可能要改的变量 这里我加了2021 还有暴露给母鸡的端口也可能要改 如果一台机器有多个 jenkins restart: always volumes: #- /data/jenkins:/var/jenkins_home:rw - jenkins_home2021:/var/jenkins_home:rw version: '3.0' volumes: jenkins_home2021: driver: local 密码就查看logs f47e158768be4c2ba0c891396cf5a55f jenkins_1 | jenkins_1 | This may also be found at: /var/jenkins_home/secrets/initialAdminPassword jenkins_1 | docker run --name=jenkins -it -u root -d -p 8080:8080 -p 50000:50000 -v /data/jenkins:/var/jenkins_home 3f08dc4f3f5d docker-compose up -d cat initialAdminPassword 05765dd93d604cd094b516ba9cc06c1a ng cat ci.conf server { listen 80; server_name market-ci.com; location / { proxy_pass http://172.31.127.223:7099; proxy_set_header X-Real-IP $remote_addr; proxy_set_header Host $host; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } } 重装要删除volumes 然后要重启 docker /home/data/docker/volumes/docker4jenkins_jenkins_home/ 如果默认 在这个目录 /var/lib/docker/volumes docker-compose up -d ERROR: The Compose file './docker-compose.yml' is invalid because: Unsupported config option for services.jenkins: 'name' 不用 volumes 会报错 [root@prod-cailuw-marke-lvs02 docker4jenkins]# docker logs 7444b6cf02a2 touch: cannot touch '/var/jenkins_home/copy_reference_file.log': Permission denied Can not write to /var/jenkins_home/copy_reference_file.log. Wrong volume permissions? touch: cannot touch '/var/jenkins_home/copy_reference_file.log': Permission denied Can not write to /var/jenkins_home/copy_reference_file.log. Wrong volume permissions? touch: cannot touch '/var/jenkins_home/copy_reference_file.log': Permission denied 居然再来一次 没有初始化界面 ? firewall-cmd --permanent --add-port=7099/tcp firewall-cmd --reload 还是不通 只能作域名了喽 hostname
alpine jenkins
Jenkins实践基础:Alpine版Jenkins(LTS版)
常用命令
重启 http://localhost:8080/restart http://localhost:8080/reload
常用参数
Transfers set Remote directory 填写 tempjar 如果是用root用户 那就是 /root/tempjar/ 有些项目改了 绝对路径居然是不行的
install plugins
change repositories
echo 'http://mirrors.aliyun.com/alpine/v3.14/main http://mirrors.aliyun.com/alpine/v3.14/community' >/etc/apk/repositories
maven
ins maven
因为jenkins本身不带maven插件,所以需要自己安装下,由于我们的虚拟机中是没有直接安装maven软件的,我们可以在全局工具配置中安装maven, 选择一个合适的版本,勾选自动安装,之后直接保存,需注意的是,现在jenkins并不会立即给你安装maven软件
这是要做的动作 note 接下来我们在插件管理中查找maven插件,我们选择好Maven Integration plugin插件,然后点击直接安装
配置maven
大家都知道我们要从maven库下载代码需要配置setting.xml,用jenkins时也需要把setting.xml配置好。在目录/docker/jenkins_home/tools/hudson.tasks.Maven_MavenInstallation/jenkins-in-maven/conf下修改setting.xml文件
新建 就可以看到 列表 有 构建一个maven 项目 安装成功
maven 配置文件
maven 配置 可以在母机修改 /docker/jenkins_home/tools/hudson.tasks.Maven_MavenInstallation/jenkins-in-maven/conf下修改setting.xml文件。 母机可能的目录 /home/data/docker/volumes/docker4jenkins_jenkins_home/_data/tools/hudson.tasks.Maven_MavenInstallation/maven3.6.2/conf
JDK
1.JDK和JRE的区别 JRE: Java Runtime Environment JDK:Java Development Kit JRE顾名思义是java运行时环境,包含了java虚拟机,java基础类库。是使用java语言编写的程序运行所需要的软件环境,是提供给想运行java程序的用户使用的。 JDK顾名思义是java开发工具包,是程序员使用java语言编写java程序所需的开发工具包,是提供给程序员使用的。JDK包含了JRE,同时还包含了编译java源码的编译器javac,还包含了很多java程序调试和分析的工具:jconsole,jvisualvm等工具软件,还包含了java程序编写所需的文档和demo例子程序。 如果你需要运行java程序,只需安装JRE就可以了。如果你需要编写java程序,需要安装JDK。 Jenkins--> Update Center--> 安装/更新 插件中 -> Oracle Java SE Development Kit Installer 可见 oracle jdk安装了 注意,自动安装jdk需要你填入oracle的账号密码,这样Jenkins才能自动帮你到oracle安装。如果没有oracle账号
ssh plgins
--> Manager plugin -> Publish Over SSH usage 全局配置 -》SSH Servers Name 可以是别名 hostname 是ip ssh 那要添加你的pri key 远程服务器添加pubkey
【Jenkins 插件】使用 Publish Over SSH 远程传输文件和自动部署
dokcer 插件
为了发布 docker
git 用户
系统-->凭证 Enter directly ->Key 添加 pri key 要在 Key 框里添加你的 pri key 不然会出这报错 Failed to connect to repository : Command "git ls-remote -h ssh://[email protected]:2222/lxtx-cailu-java-projects/lxtx-cailu-market.git HEAD" returned status code 128: stdout: stderr: Permission denied (publickey). fatal: Could not read from remote repository. Please make sure you have the correct access rights and the repository exists. 行情改成这样的 git ssh://[email protected]:2222/lxtx-cailu-java-projects/lxtx-cailu-market.git
数据库更新
liquibase
使用 LiquiBase 管理数据库变更 数据库版本管理(含与Spring Boot Gradle Liquibase 插件整合的demo)
npm yarn
#on contain apk add --update nodejs npm apk add --update yarn #web界面也要加上 相关的plugins nodejs npm yarn 改源 最好写文件 npm config set registry https://registry.nlark.com/ npm config set electron_mirror https://npm.taobao.org/mirrors/electron/ yarn config set sass_binary_site https://npm.taobao.org/mirrors/node-sass/
golang
#install package apk add --no-cache git make musl-dev go rsync # 进入项目代码所在目录 cd ${WORKSPACE}/www # GO编译项目代码成可执行文件 #/usr/local/go/bin/go build -o chat-auto-service . go build -o chat-auto-service . # 同步可执行文件到正式环境 env RSYNC_PASSWORD=pass rsync -az --port=873 $WORKSPACE/www/chat-auto [email protected]::lc-chat-auto-service
php
可见有多个版本的 php https://wiki.alpinelinux.org/wiki/Nginx_with_PHP
apk add php composer apk add php7-fpm php7-mcrypt php7-soap php7-openssl php7-gmp php7-pdo_odbc php7-json php7-dom php7-pdo php7-zip php7-mysqli php7-sqlite3 php7-apcu php7-pdo_pgsql php7-bcmath php7-gd php7-odbc php7-pdo_mysql php7-pdo_sqlite php7-gettext php7-xmlreader php7-xmlrpc php7-bz2 php7-iconv php7-pdo_dblib php7-curl php7-ctype php7 -v apk add php5-fpm php5-mcrypt php5-soap php5-openssl php5-gmp php5-pdo_odbc php5-json php5-dom php5-pdo php5-zip php5-mysql php5-mysqli php5-sqlite3 php5-apcu php5-pdo_pgsql php5-bcmath php5-gd php5-xcache php5-odbc php5-pdo_mysql php5-pdo_sqlite php5-gettext php5-xmlreader php5-xmlrpc php5-bz2 php5-memcache php5-mssql php5-iconv php5-pdo_dblib php5-curl php5-ctype #ss lc项目打包要用到 apk add php composer apk add php7-redis php7-xmlwriter php7-simplexml php7-sockets php7-tokenizer 大不了 php5.6源码嘛
python plugin
apk add python2 Jenkins 执行python脚本 安装如下两个 plugin
python_plugin python_wrapper_plugin
任务中添加python脚本即可,点击保存时候,自动会在下图中目录生成.py文件 jenkins执行python脚本的方法
生成SSHKey
先进入容器 docker exec -it jenkins /bin/bash 进入容器后生成sshkey ssh-keygen -t dsa -C "[email protected]" 获取公钥 1.进入容器 2. 直接cat 一下 mount的目录 eg tail /var/lib/docker/volumes/jenkins/_data/.ssh/id_rsa.pub
jenkins时区设置
【系统管理】-【脚本命令行】里运行 System.setProperty('org.apache.commons.jelly.tags.fmt.timeZone', 'Asia/Shanghai') 如果想永久 还是加在 yaml文件里 时间问题 以前思源的文档有 -v /etc/localtime:/etc/localtime 让容器使用和服务器同样的时间设置
https://wiki.jenkins.io/display/JENKINS/Change+time+zone
nginx config Reverse proxy - Nginx
trouble
第二天不能登录 这个是输入错了吧 Invalid username or password
迁移 jenkins 要注意的
java.io.IOException: Cannot run program "/var/jenkins_home/tools/hudson.model.JDK/jdk/bin/java" (in directory "/var/jenkins_home/workspace/pro-cailu-market"): error=2, No such file or directory maven 要重新 配置 全局-->maven 安装 hudson.AbortException: Unable to install JDK unless a valid username/password is provided. 填写 oracle用户和密码 原来 用户 密码是oracle提供的 http://market-ci.com/descriptorByName/hudson.tools.JDKInstaller/enterCredential 要重新添加 git 用户 和密码 Remote directory 填写 tempjar 如果是用root用户 那就是 /root/tempjar/
Jenkins安装插件提速 插件换源
现在感觉不改更快 docker-compose exec --user root jenkins bash find / -name default.json #如果是原生的安装 cd /var/jenkins_home/updates #还是用 ! 不然#的可能在alpine不生效 sed -i 's!https://updates.jenkins.io/download!https://mirrors.tuna.tsinghua.edu.cn/jenkins!g' default.json sed -i 's!http://updates.jenkins-ci.org/download!https://mirrors.tuna.tsinghua.edu.cn/jenkins!g' default.json sed -i 's!http://www.google.com!https://www.baidu.com!g' default.json # #号的放弃了 Friday May six 2022 sed -i 's#https://updates.jenkins.io/download#https://mirrors.tuna.tsinghua.edu.cn/jenkins#g' default.json sed -i 's#http://updates.jenkins-ci.org/download#https://mirrors.tuna.tsinghua.edu.cn/jenkins#g' default.json sed -i 's#http://www.google.com#https://www.baidu.com#g' default.json 重启生效 docker-compose restart jenkins #不用下面这个吧 http://192.168.10.54:7099/restart web界面在线修改 插件镜像 安装插件可能失败,大概率是因为网络原因,所以这里修改一下插件的安装镜像地址。 打开 系统管理->插件管理->高级->升级站点,改成清华大学的镜像地址 https://mirrors.tuna.tsinghua.edu.cn/jenkins/updates/update-center.json 或者直接在母机 /var/lib/docker/volumes/jenkins_jenkins_home/_data/updates
https://blog.csdn.net/weixin_43557605/article/details/104587304
docker-compose 相关文件被删除
处理办法 数据目录(我用了默认的)没被 删除 ,再搞个 docker-compose.yml 文件就行了 和对应目录
Jenkins忘记密码
#2021 试过有效果 /var/jenkins_home/users/admin/config.xml 新版本 jenkins_jenkins_home/_data/users/admin_1216381497456990300 cat config.xml | grep passwordHash <passwordHash>#jbcrypt:$2a$10$MiIVR0rr/UhQBqT.bBq0QehTiQVqgNpUGyWW2nJObaVAM/2xSQdSq</passwordHash> 123456加密后: #jbcrypt:$2a$10$MiIVR0rr/UhQBqT.bBq0QehTiQVqgNpUGyWW2nJObaVAM/2xSQdSq 修改 /users/admin/comfig.xml 文件后,保存重新启动Jenkins程序。 再以用户名admin 密码123456 成功登录 #note 这是基于docker的jenkins jenkins@c58dc265c073:~/users$ pwd /var/jenkins_home/users cat users.xml <entry> <string>lxtxadmin</string> <string>lxtxadmin_7295399102977240796</string> cd lxtxadmin_7295399102977240796/ cat config.xml | grep passwordHash <passwordHash>#jbcrypt:$2a$10$h/LCaTsmNht3F04LbZPsY.OtTyx1e/P7pit6Te7KjGVXkhe/caqyW</passwordHash> #jbcrypt:$2a$10$MiIVR0rr/UhQBqT.bBq0QehTiQVqgNpUGyWW2nJObaVAM/2xSQdSq 123456 这个写法有问题啦 前面不是固定的啦 sed -i 's!#jbcrypt:$2a$10$h/LCaTsmNht3F04LbZPsY.OtTyx1e/P7pit6Te7KjGVXkhe/caqyW!#jbcrypt:$2a$10$DdaWzN64JgUtLdvxWIflcuQu2fgrrMSAMabF5TSrGK5nXitqK9ZMS!' config.xml 后者是111111的hash值 6个1 docker-compose restart 当然 最后记得要改回得比较强的密码喽
该Jenkins实例似乎已离线。
Jenkins 2.176.3 原因 近来网络管理又严格了 updates/default.json jenkins在下载插件之前会先检查网络连接,其会读取这个文件中的网址。默认是: 访问谷歌 处理办法 改成可以直接访问的就行了 jenkins@jenkins-hellotest:~/updates$ pwd /var/jenkins_home/updates sed -i 's/google/baidu/' default.json
打开主页空白
打开 http://192.168.10.214:7099/pluginManager/advanced 最后要恢复回来 ,不然打开主页空白呢 http://updates.jenkins.io/update-center.json https://mirrors.tuna.tsinghua.edu.cn/jenkins/updates/update-center.json /pluginManager/advanced 改回原来的 http://updates.jenkins.io/update-center.json
https://blog.csdn.net/harry5508/article/details/91958249
https://www.cnblogs.com/effortsing/p/10013412.html
https://blog.csdn.net/huoyunshen88/article/details/8509886
https://www.jianshu.com/p/1e411d225186
web打不开 wrapper Up (unhealthy)
重启并等 一下下 过程如下 docker-compose ps Name Command State Ports ------------------------------------------------------------------------------------------------------------------- gitlab_web_1 /assets/wrapper Up (unhealthy) 0.0.0.0:2222->22/tcp, 0.0.0.0:4433->443/tcp, 0.0.0.0:7080->80/tcp root@jenkins2020:/data/apps/gitlab# docker-compose restart Restarting gitlab_web_1 ... done root@jenkins2020:/data/apps/gitlab# docker-compose ps Name Command State Ports -------------------------------------------------------------------------------------------------------------------------- gitlab_web_1 /assets/wrapper Up (health: starting) 0.0.0.0:2222->22/tc docker-compose ps Name Command State Ports ----------------------------------------------------------------------------------------------------------------- gitlab_web_1 /assets/wrapper Up (healthy) 0.0.0.0:2222->22/tcp, 0.0.0.0:4433->443/tcp, 0.0.0.0:7080->80/tcp root@jenkins2020:/data/apps/gitlab#
删除home数据目录
mkdir -p /var/lib/docker/volumes/jenkins_jenkins_home/_data #可能要创建回去
re
https://hub.docker.com/r/jenkins/jenkins
Docker+Jenkins持续集成环境(1)使用Docker搭建Jenkins+Docker持续集成环境
http://www.itmuch.com/work/jenkins-in-action/
Install Jenkins using Docker Compose
jenkins自动化部署+git安装配置(多秘钥)+maven安装配置