“Jenkins进行持续集成”的版本间的差异
(未显示同一用户的62个中间版本) | |||
第1行: | 第1行: | ||
+ | |||
+ | |||
+ | |||
仔细总结一下,我们会发现,除了编写代码,我们每天有相当一部分时间花在了编 译、运行单元测试、生成文档、打包和部署等烦琐且不起眼的工作上,这就是构建。如果我们现在还手工这样做,那成本也太高了,于是有人用软件的方法让这一系 列工作完全自动化,使得软件的构建可以像全自动流水线一样,只需要一条简单的命令,所有烦琐的步骤都能够自动完成,很快就能得到最终结果。 | 仔细总结一下,我们会发现,除了编写代码,我们每天有相当一部分时间花在了编 译、运行单元测试、生成文档、打包和部署等烦琐且不起眼的工作上,这就是构建。如果我们现在还手工这样做,那成本也太高了,于是有人用软件的方法让这一系 列工作完全自动化,使得软件的构建可以像全自动流水线一样,只需要一条简单的命令,所有烦琐的步骤都能够自动完成,很快就能得到最终结果。 | ||
第4行: | 第7行: | ||
Maven真比自己的“规范化Ant”强大?其实他不知道自己只是在重新发明轮子,Maven已经有一大把现成的插件,全世界都在用,你自己不用写任何代码! | Maven真比自己的“规范化Ant”强大?其实他不知道自己只是在重新发明轮子,Maven已经有一大把现成的插件,全世界都在用,你自己不用写任何代码! | ||
+ | =see also= | ||
+ | [[Jenkins shared library 共享库示例]] | ||
+ | =现在一般更新在 站内资源 如下 [[基于Docker的Jenkins持续集成]]= | ||
+ | |||
+ | [[基于Docker的Jenkins持续集成]] | ||
− | =常用CI/CD= | + | jenkins-cli |
+ | |||
+ | =常用CI/CD CI, CD and CD= | ||
+ | continuous[kənˈtɪnjuːəs] adj.连续的 | ||
+ | deliver [dɪˈlɪvər] v.交付 | ||
+ | continuous delivery, and continuous deployment. | ||
+ | |||
+ | CI, CD AND CD | ||
+ | CI很容易理解,就是持续集成。但是CD既可以指代码持续交付(CONTINUOUS DELIVERY),也可理解为代码持续部署 (CONTINUOUS DEPLOYMENT)。CI和CD之间有很多相似的部分,但是也有很大的区别。 | ||
+ | |||
+ | 持续集成(CONTINUOUS INTEGRATION) | ||
+ | |||
+ | 在持续集成环境中,开发人员将会频繁的提交代码到主干。这些新提交在最终合并到主线之前,都需要通过编译和自动化测试流进行验证。这样做是基于之前持续集成过程中很重视自动化测试验证结果,以保障所有的提交在合并主线之后的质量问题,对可能出现的一些问题进行预警。 | ||
+ | |||
+ | |||
+ | 持续交付(CONTINUOUS DELIVERY) | ||
+ | |||
+ | 持续交付就是讲我们的应用发布出去的过程。这个过程可以确保我们尽可能快的实现交付。这就意味着除了自动化测试,我们还需要有自动化的发布流,以及通过一个按键就可以随时随地实现应用的部署上线。 | ||
+ | |||
+ | 通过持续交付,您可以决定每天,每周,每两周发布一次,这完全可以根据自己的业务进行设置。 | ||
+ | |||
+ | 但是,如果您真的希望体验持续交付的优势,就需要先进行小批量发布,尽快部署到生产线,以便在出现问题时方便进行故障排除。 | ||
+ | |||
+ | 持续部署(CONTINUOUS DEPLOYMENT) | ||
+ | |||
+ | 如果我们想更加深入一步的话,就是持续部署了。通过这个方式,任何修改通过了所有已有的工作流就会直接和客户见面。没有人为干预(没有一键部署按钮),只有当一个修改在工作流中构建失败才能阻止它部署到产品线。 | ||
+ | |||
+ | 持续部署是一个很优秀的方式,可以加速与客户的反馈循环,但是会给团队带来压力,因为不再有“发布日”了。开发人员可以专注于构建软件,他们看到他们的修改在他们完成工作后几分钟就上线了。基本上,当开发人员在主分支中合并一个提交时,这个分支将被构建、测试,如果一切顺利,则部署到生产环境中。 | ||
+ | |||
+ | |||
+ | |||
+ | [https://zhuanlan.zhihu.com/p/31097868 一文帮你秒懂CI, CD AND CD] | ||
+ | |||
+ | [https://www.redhat.com/zh/topics/devops/what-is-ci-cd CI/CD是什么?如何理解持续集成、持续交付和持续部署] | ||
+ | |||
+ | [https://jenkins-zh.cn/wechat/articles/2019/04/2019-04-12-what-is-cicd/ 什么是 CI/CD?] | ||
+ | |||
+ | CI 持续集成(Continuous | ||
+ | |||
+ | Integration) | ||
+ | |||
+ | CD 持续部署(Continuous Deployment | ||
最最流行的,也是使用最多的Jenkins | 最最流行的,也是使用最多的Jenkins | ||
有着持续集成DNA的ThoughtWorks GO。理念:"Deployment as pipeline" (华为容器平台应该是基于GO做的二次开发实现) | 有着持续集成DNA的ThoughtWorks GO。理念:"Deployment as pipeline" (华为容器平台应该是基于GO做的二次开发实现) | ||
第12行: | 第61行: | ||
专为开源打造的Travis CI,与Github紧密集成 | 专为开源打造的Travis CI,与Github紧密集成 | ||
使用Python语言实现的Buildbot,相信Pythoner看到会喜欢 | 使用Python语言实现的Buildbot,相信Pythoner看到会喜欢 | ||
+ | |||
+ | [https://www.redhat.com/zh/topics/devops/what-is-ci-cd CI/CD是什么?如何理解持续集成、持续交付和持续部署] | ||
=安装= | =安装= | ||
− | == | + | == 通过docker-compose安装== |
[[基于Docker的Jenkins持续集成]] | [[基于Docker的Jenkins持续集成]] | ||
− | == | + | == apt install == |
+ | <pre> | ||
+ | #sep 2023 debian | ||
+ | 11.0 只是感觉文档有点老 confused | ||
+ | https://pkg.jenkins.io/debian-stable/ | ||
+ | |||
+ | curl -fsSL https://pkg.jenkins.io/debian-stable/jenkins.io-2023.key | sudo tee \ | ||
+ | /usr/share/keyrings/jenkins-keyring.asc > /dev/null | ||
+ | |||
+ | echo deb [signed-by=/usr/share/keyrings/jenkins-keyring.asc] \ | ||
+ | https://pkg.jenkins.io/debian-stable binary/ | sudo tee \ | ||
+ | /etc/apt/sources.list.d/jenkins.list > /dev/null | ||
+ | |||
+ | |||
+ | sudo apt-get update | ||
+ | sudo apt-get install fontconfig openjdk-11-jre | ||
+ | sudo apt-get install jenkins | ||
+ | |||
+ | |||
+ | |||
+ | 正在读取状态信息... 完成 | ||
+ | 有 2157 个软件包可以升级。请执行 ‘apt list --upgradable’ 来查看它们。 | ||
+ | W: https://pkg.jenkins.io/debian-stable/binary/Release.gpg: Key is stored in legacy trusted.gpg keyring (/etc/apt/trusted.gpg), see the DEPRECATION section in apt-key(8) for details. | ||
+ | |||
+ | 重新导入一下 key | ||
+ | root@myxps:/etc/apt/sources.list.d# curl -fsSL https://pkg.jenkins.io/debian-stable/jenkins.io.key | sudo tee \ | ||
+ | /usr/share/keyrings/jenkins-keyring.asc > /dev/null | ||
+ | |||
+ | #这样就更新为最新的lts | ||
+ | sudo apt -y install jenkins | ||
+ | </pre> | ||
+ | https://pkg.jenkins.io/debian-stable/ | ||
+ | |||
+ | === 填写新仓库提示No ECDSA红字错误=== | ||
+ | |||
+ | 我的jenkins是docker部署的 | ||
+ | 登录容器 apk add git 然后再把你的key 放入 并 | ||
+ | |||
+ | 需要在jenkins的容器里 执行以下命令访问git上的仓库地址,把git的主机添加到/root/.ssh/known_hosts(执行命令前known_hosts这个文件是不存在的,执行后就有了) | ||
+ | https://blog.csdn.net/bigwood99/article/details/107073603 | ||
+ | |||
+ | == war 可以自定义目录== | ||
+ | <pre> | ||
+ | |||
+ | sudo apt install openjdk-11-jre | ||
+ | sudo JENKINS_HOME=/home/evan/data/apps/war-jenkins/ java -jar /home/evan/data/apps/war-jenkins/jenkins.war | ||
+ | |||
+ | |||
+ | |||
+ | #troubleshooting | ||
+ | root@myxps:~# JENKINS_HOME=/home/evan/data/apps/war-jenkins/ java -jar /home/evan/data/apps/war-jenkins/jenkins.war | ||
+ | Running with Java 8 from /usr/lib/jvm/java-8-openjdk-amd64/jre, which is older than the minimum required version (Java 11). | ||
+ | Supported Java versions are: [11, 17] | ||
+ | See https://jenkins.io/redirect/java-support/ for more information. | ||
+ | |||
+ | ln -s /usr/lib/jvm/java-11-openjdk-amd64/bin/java /etc/alternatives/java | ||
+ | |||
+ | </pre> | ||
+ | https://www.jenkins.io/doc/book/installing/war-file/ | ||
+ | |||
+ | ==已放弃普通安装已放弃的方法== | ||
ip 192.168.0.16 | ip 192.168.0.16 | ||
<pre> | <pre> | ||
+ | 已放弃 | ||
docker pull jenkins | docker pull jenkins | ||
第117行: | 第229行: | ||
ex command #记得要要全局那加ssh server | ex command #记得要要全局那加ssh server | ||
+ | |||
+ | |||
+ | </pre> | ||
+ | |||
+ | |||
+ | ==jenkins slave == | ||
+ | === k8s 创建jenkins slave Pod节点 详情参考 [[How to Setup Jenkins Build Agents on Kubernetes Pods]] === | ||
+ | <pre> | ||
+ | 选择一个或多个节点作为k8s 创建jenkins slave Pod的节点 | ||
+ | |||
+ | 配置参考可见此url | ||
+ | https://github.com/sunweisheng/Jenkins/blob/master/Jenkins-Kubernetes.md | ||
+ | |||
+ | 创建一个流水线 job | ||
+ | #内容差不多这样 | ||
+ | podTemplate { | ||
+ | node(POD_LABEL) { | ||
+ | stage('echo something') { | ||
+ | sh 'echo hello world from pod test ' | ||
+ | } | ||
+ | } | ||
+ | } | ||
+ | |||
+ | 运动成功的结果 差不多这些 | ||
+ | |||
+ | tarted by user evan | ||
+ | [Pipeline] Start of Pipeline | ||
+ | [Pipeline] podTemplate | ||
+ | [Pipeline] { | ||
+ | [Pipeline] node | ||
+ | Created Pod: kubernetes-study default/testoct23pm-2-bfcr1-fzhwb-cklsv | ||
+ | Still waiting to schedule task | ||
+ | Waiting for next available executor on ‘testoct23pm-2-bfcr1-fzhwb-cklsv’ | ||
+ | 代理 testoct23pm-2-bfcr1-fzhwb-cklsv 由模板 testoct23pm_2-bfcr1-fzhwb 提供 | ||
+ | --- | ||
+ | apiVersion: "v1" | ||
+ | kind: "Pod" | ||
+ | metadata: | ||
+ | annotations: | ||
+ | buildUrl: "http://192.168.10.105:8080/job/testoct23pm/2/" | ||
+ | runUrl: "job/testoct23pm/2/" | ||
+ | labels: | ||
+ | jenkins: "slave" | ||
+ | jenkins/label-digest: "a0fe9942b760b4677c42994a4fde67d00032b3df" | ||
+ | jenkins/label: "testoct23pm_2-bfcr1" | ||
+ | name: "testoct23pm-2-bfcr1-fzhwb-cklsv" | ||
+ | namespace: "default" | ||
+ | |||
+ | |||
+ | Running on testoct23pm-2-bfcr1-fzhwb-cklsv in /home/jenkins/agent/workspace/testoct23pm | ||
+ | [Pipeline] { | ||
+ | [Pipeline] stage | ||
+ | [Pipeline] { (echo something) | ||
+ | [Pipeline] sh | ||
+ | + echo hello world from pod test | ||
+ | hello world from pod test | ||
+ | [Pipeline] } | ||
+ | [Pipeline] // stage | ||
+ | [Pipeline] } | ||
+ | [Pipeline] // node | ||
+ | [Pipeline] } | ||
+ | [Pipeline] // podTemplate | ||
+ | [Pipeline] End of Pipeline | ||
+ | Finished: SUCCESS | ||
+ | |||
+ | or | ||
+ | |||
+ | Started by user evan | ||
+ | [Pipeline] Start of Pipeline | ||
+ | [Pipeline] podTemplate | ||
+ | [Pipeline] { | ||
+ | [Pipeline] node | ||
+ | Created Pod: kubernetes-study default/testoct23pm-1-v6jx5-brq84-ns0x8 | ||
+ | Still waiting to schedule task | ||
+ | ‘testoct23pm-1-v6jx5-brq84-ns0x8’ is offline | ||
+ | 代理 testoct23pm-1-v6jx5-brq84-ns0x8 由模板 testoct23pm_1-v6jx5-brq84 提供 | ||
+ | --- | ||
+ | apiVersion: "v1" | ||
+ | kind: "Pod" | ||
+ | |||
+ | |||
+ | eg2 | ||
+ | |||
+ | podTemplate(label: 'build', containers: [ | ||
+ | containerTemplate(name: 'docker', image: 'docker', command: 'cat', ttyEnabled: true) | ||
+ | ], | ||
+ | volumes: [ | ||
+ | hostPathVolume(mountPath: '/var/run/docker.sock', hostPath: '/var/run/docker.sock'), | ||
+ | ] | ||
+ | ) { | ||
+ | node('build') { | ||
+ | container('docker') { | ||
+ | sh 'hostname' | ||
+ | sh 'ip a' | ||
+ | } | ||
+ | } | ||
+ | } | ||
+ | |||
+ | |||
+ | </pre> | ||
+ | |||
+ | ===普通jenkins slave === | ||
+ | <pre> | ||
+ | |||
+ | sudo java -jar agent.jar -jnlpUrl http://192.168.10.105:8080/computer/jenkins%2Dslave1/jenkins-agent.jnlp -secret d3978968148304770e0ecf18f8dd6e18ed61580afde6086ea03113c997fc35bf -workDir "/tmp/jenkins" | ||
+ | |||
+ | 问题 | ||
+ | jenkins slave ava.lang.Exception: The server rejected the connection: None of the protocols are enabled | ||
+ | |||
+ | Jenkins -> Global Security Configuration -> Agents -> Agent protocols -> Inbound TCP Agent Protocol/4 (TLS encryption) | ||
+ | |||
+ | 代理 指定端口 50000 | ||
+ | |||
+ | 代理协议 Java Web Start Agent Protocol/4 (TLS 加密) | ||
第132行: | 第358行: | ||
==maven== | ==maven== | ||
<pre> | <pre> | ||
+ | |||
+ | 我试过 好像不用安装 jdk的呀 docker化的jenkins | ||
+ | |||
+ | 安装在configureTools 全局配置那里 要加上maven 和填写版本 以这个为目录名 例如下面的maven3.6.2 | ||
+ | |||
+ | |||
Build->Goals and options ->clean install -Pbeta -Dmaven.test.skip=true | Build->Goals and options ->clean install -Pbeta -Dmaven.test.skip=true | ||
第142行: | 第374行: | ||
===maven 配置文件 === | ===maven 配置文件 === | ||
− | <pre>maven 配置 可以在母机修改 | + | <pre>maven 配置 可以在母机修改 注意 要先至少跑个工程后 才会安装maven 生成这个目录了 |
+ | |||
+ | 有时要密码的 ,格式要小心 烦死了 | ||
+ | |||
+ | /data/docker/volumes/docker4jenkins_jenkins_home/_data/tools/hudson.tasks.Maven_MavenInstallation/maven/conf/settings.xml | ||
/docker/jenkins_home/tools/hudson.tasks.Maven_MavenInstallation/jenkins-in-maven/conf下修改setting.xml文件。 | /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 | /home/data/docker/volumes/docker4jenkins_jenkins_home/_data/tools/hudson.tasks.Maven_MavenInstallation/maven3.6.2/conf | ||
+ | |||
第163行: | 第400行: | ||
164 </mirror> | 164 </mirror> | ||
165 </mirrors> | 165 </mirrors> | ||
− | + | ||
+ | |||
+ | 公用的方便安装的如下配置 | ||
+ | <mirrors> | ||
+ | <!-- mirror | ||
+ | | Specifies a repository mirror site to use instead of a given repository. The repository that | ||
+ | | this mirror serves has an ID that matches the mirrorOf element of this mirror. IDs are used | ||
+ | | for inheritance and direct lookup purposes, and must be unique across the set of mirrors. | ||
+ | | | ||
+ | <mirror> | ||
+ | <id>mirrorId</id> | ||
+ | <mirrorOf>repositoryId</mirrorOf> | ||
+ | <name>Human Readable Name for this Mirror.</name> | ||
+ | <url>http://my.repository.com/repo/path</url> | ||
+ | </mirror> | ||
+ | --> | ||
+ | <mirror> | ||
+ | <id>alimaven</id> | ||
+ | <name>aliyun maven</name> | ||
+ | <url>http://maven.aliyun.com/nexus/content/groups/public/</url> | ||
+ | <mirrorOf>central</mirrorOf> | ||
+ | </mirror> | ||
+ | </mirrors> | ||
+ | |||
+ | |||
+ | #lx | ||
+ | <servers> | ||
+ | <server> | ||
+ | <id>nexus</id> | ||
+ | <username>admin</username> | ||
+ | <password>lxtxadmin123</password> | ||
+ | </server> | ||
+ | </servers> | ||
+ | |||
+ | <mirrors> | ||
+ | <mirror> | ||
+ | <id>nexus</id> | ||
+ | <mirrorOf>*</mirrorOf> | ||
+ | <url>http://192.168.4.189:8081/repository/maven-public/</url> | ||
+ | </mirror> | ||
+ | <!-- <mirror>--> | ||
+ | <!-- <id>nexus-aliyun</id>--> | ||
+ | <!-- <mirrorOf>central</mirrorOf>--> | ||
+ | <!-- <name>Nexus aliyun</name>--> | ||
+ | <!-- <url>http://maven.aliyun.com/nexus/content/groups/public</url>--> | ||
+ | <!-- </mirror>--> | ||
+ | |||
+ | </mirrors> | ||
</pre> | </pre> | ||
+ | [https://blog.csdn.net/w13511069150/article/details/93161141 Jenkins修改Maven配置] | ||
+ | |||
+ | [https://blog.csdn.net/xxsstf/article/details/84991931 Jenkins使用, maven插件配置修改] | ||
+ | |||
+ | |||
+ | [https://yq.aliyun.com/articles/752222 Maven国内可用下载速度快的仓库镜像(阿里Maven镜像地址)] | ||
+ | |||
+ | [https://www.cnblogs.com/xiao987334176/p/11433636.html Jenkins配置maven] | ||
===snapshot快照仓库和release发布仓库=== | ===snapshot快照仓库和release发布仓库=== | ||
第197行: | 第489行: | ||
==android== | ==android== | ||
[ https://blog.csdn.net/youshi520000/article/details/81027940 Android 使用 Jenkins 实现自动化打包【流程】&【踩坑] | [ https://blog.csdn.net/youshi520000/article/details/81027940 Android 使用 Jenkins 实现自动化打包【流程】&【踩坑] | ||
+ | |||
+ | |||
+ | == Jenkins的初级应用(2)-Invoke Phing targets== | ||
+ | [https://www.cnblogs.com/hodge01/p/9367498.html Jenkins的初级应用(2)-Invoke Phing targets] | ||
==启动== | ==启动== | ||
第215行: | 第511行: | ||
=权限控制= | =权限控制= | ||
− | + | [https://www.cnblogs.com/jabbok/p/12814052.html jenkins使用ldap权限管理 ] | |
==Role-based Authorization Strategy== | ==Role-based Authorization Strategy== | ||
− | Role-based Authorization Strategy | + | 可选插件-->Role-based Authorization Strategy |
超级用户 root root | 超级用户 root root | ||
other evan | other evan | ||
− | group ops java admin | + | group ops java admin |
==基于项目(job)== | ==基于项目(job)== | ||
<pre> | <pre> | ||
+ | --> Manage Roles | ||
+ | |||
Project roles 创建一个 dev 只配置所以 dev开头的内网项目 | Project roles 创建一个 dev 只配置所以 dev开头的内网项目 | ||
Role to add dev | Role to add dev | ||
Pattern dev.* #配置 | Pattern dev.* #配置 | ||
+ | |||
选择【 Manage Roles】 | 选择【 Manage Roles】 | ||
第237行: | 第536行: | ||
然后把你的号添加到 Global roles | 然后把你的号添加到 Global roles | ||
− | Item roles 里面 加入你的号 并勾上 dev | + | Assign Roles-- Item roles 里面 加入你的号 并勾上 dev |
− | 注意: Global roles | + | 注意: Global roles 必要有 你要给别人用的用户名,不登录了什么 都没提示全局没有读权限 </pre> |
+ | |||
+ | ==godd lxtx eg== | ||
+ | <pre> | ||
+ | 2021年 11月 17日 星期三 19:46:26 | ||
+ | 这个不错 不过还要用视图,不要让见到太多 | ||
+ | |||
+ | pre 倒好这里有个前端小哥 就叫 wusiyi | ||
+ | |||
+ | Manage Roles 角色管理 -- Global roles: Role to add role name 为desk 全给read | ||
+ | |||
+ | Item roles : role to add :Frontend_h5 Pattern: (?i)stage-.*|prod-hailuo-sdk-doc|bcb-blockchain-h5|k8s-local-nuxt-snsdev-hailuo-open-website 这个权限就看你给了 | ||
+ | |||
+ | |||
+ | |||
+ | Assign Roles分配角色 Global roles: wusiyi 选择在 desk ; Item roles:Frontend_h5 和上面的 role to add 对应 | ||
+ | |||
+ | </pre> | ||
==权限see also== | ==权限see also== | ||
第251行: | 第567行: | ||
[https://www.jianshu.com/p/6c274d9b22ad Jenkins自动化部署-权限管控篇 (六)] | [https://www.jianshu.com/p/6c274d9b22ad Jenkins自动化部署-权限管控篇 (六)] | ||
+ | |||
+ | [https://www.cnblogs.com/zphqq/p/10044597.html jenkins Manage and Assign Roles使用 ] | ||
+ | |||
+ | [https://trainoo.gitee.io/2019/12/28/Jenkins-role-base-authorization-strategy-plugin/ Jenkins的权限管理] | ||
=插件= | =插件= | ||
− | + | [https://www.cnblogs.com/mingerlcm/p/12643710.html Jenkins 插件管理] | |
==dashboard 插件== | ==dashboard 插件== | ||
dashboard 插件 [https://wiki.jenkins-ci.org/display/JENKINS/Dashboard+View Dashboard View] | dashboard 插件 [https://wiki.jenkins-ci.org/display/JENKINS/Dashboard+View Dashboard View] | ||
第260行: | 第580行: | ||
== Wall display== | == Wall display== | ||
用来将 jobs 的状态更加直观地显示在大屏幕上 | 用来将 jobs 的状态更加直观地显示在大屏幕上 | ||
+ | |||
+ | 国内的源:https://mirrors.tuna.tsinghua.edu.cn/jenkins/plugins/ | ||
=== ssh server=== | === ssh server=== | ||
第275行: | 第597行: | ||
https://ask.csdn.net/questions/379784 | https://ask.csdn.net/questions/379784 | ||
− | =jenkins = | + | =NODE= |
+ | jenkins plugin 要安装 node | ||
+ | apk add --no-cache python | ||
+ | |||
+ | alpine 里面也要安装 node.js alpine | ||
+ | https://wiki.linuxchina.net/index.php/Alpine#docker | ||
+ | |||
+ | |||
+ | [https://blog.csdn.net/wanchaopeng/article/details/87934293 jenkins打包nodejs] | ||
+ | |||
+ | [https://www.cnblogs.com/vipzhou/p/7890016.html jenkins学习之自动打包构建nodejs应用] | ||
+ | =php jenkins 实现PHP持续集成部署= | ||
+ | |||
+ | [[jenkins实现PHP持续集成部署]] | ||
=xk= | =xk= | ||
第308行: | 第643行: | ||
== offline == | == offline == | ||
点击Continue,大部分人都会出现这个界面,毕竟在天朝,我们先选择跳过 | 点击Continue,大部分人都会出现这个界面,毕竟在天朝,我们先选择跳过 | ||
+ | |||
+ | |||
+ | ==project lxtx-hello-admin-dao: Could not resolve dependencies for project com.lxtx.hello:lxtx == | ||
+ | <pre> | ||
+ | Waiting for Jenkins to finish collecting data | ||
+ | [ERROR] Failed to execute goal on project lxtx-hello-admin-dao: Could not resolve dependencies for project com.lxtx.hello:lxtx-hello-admin-dao:jar:0.0.1: Could not find artifact com.lxtx.im:lxtx-admin-base-service:jar:0.1.6 in central (https://repo.maven.apache.org/maven2) -> [Help 1] | ||
+ | [ERROR] | ||
+ | [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch. | ||
+ | [ERROR] Re-run Maven using the -X switch to enable full debug logging. | ||
+ | [ERROR] | ||
+ | [ERROR] For more information about the errors and possible solutions, please read the following articles: | ||
+ | [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/DependencyResolutionException | ||
+ | [ERROR] | ||
+ | [ERROR] After correcting the problems, you can resume the build with the command | ||
+ | [ERROR] mvn <goals> -rf :lxtx-hello-admin-dao | ||
+ | </pre> | ||
+ | |||
+ | === soult=== | ||
+ | <pre> | ||
+ | |||
+ | docker dir | ||
+ | /var/jenkins_home/.m2/settings.xml | ||
+ | |||
+ | 母鸡目录 | ||
+ | /volumes/docker4jenkins_jenkins_home/_data/.m2/settings.xml | ||
+ | |||
+ | <?xml version="1.0" encoding="UTF-8"?> | ||
+ | |||
+ | <!-- | ||
+ | Licensed to the Apache Software Foundation (ASF) under one | ||
+ | or more contributor license agreements. See the NOTICE file | ||
+ | distributed with this work for additional information | ||
+ | regarding copyright ownership. The ASF licenses this file | ||
+ | to you under the Apache License, Version 2.0 (the | ||
+ | "License"); you may not use this file except in compliance | ||
+ | with the License. You may obtain a copy of the License at | ||
+ | |||
+ | http://www.apache.org/licenses/LICENSE-2.0 | ||
+ | |||
+ | Unless required by applicable law or agreed to in writing, | ||
+ | software distributed under the License is distributed on an | ||
+ | "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
+ | KIND, either express or implied. See the License for the | ||
+ | specific language governing permissions and limitations | ||
+ | under the License. | ||
+ | --> | ||
+ | |||
+ | <!-- | ||
+ | | This is the configuration file for Maven. It can be specified at two levels: | ||
+ | | | ||
+ | | 1. User Level. This settings.xml file provides configuration for a single user, | ||
+ | | and is normally provided in ${user.home}/.m2/settings.xml. | ||
+ | | | ||
+ | | NOTE: This location can be overridden with the CLI option: | ||
+ | | | ||
+ | | -s /path/to/user/settings.xml | ||
+ | | | ||
+ | | 2. Global Level. This settings.xml file provides configuration for all Maven | ||
+ | | users on a machine (assuming they're all using the same Maven | ||
+ | | installation). It's normally provided in | ||
+ | | ${maven.home}/conf/settings.xml. | ||
+ | | | ||
+ | | NOTE: This location can be overridden with the CLI option: | ||
+ | | | ||
+ | | -gs /path/to/global/settings.xml | ||
+ | | | ||
+ | | The sections in this sample file are intended to give you a running start at | ||
+ | | getting the most out of your Maven installation. Where appropriate, the default | ||
+ | | values (values used when the setting is not specified) are provided. | ||
+ | | | ||
+ | |--> | ||
+ | <settings xmlns="http://maven.apache.org/SETTINGS/1.0.0" | ||
+ | xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
+ | xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd"> | ||
+ | <!-- localRepository | ||
+ | | The path to the local repository maven will use to store artifacts. | ||
+ | | | ||
+ | | Default: ${user.home}/.m2/repository | ||
+ | --> | ||
+ | <localRepository>D:\tools\apache-maven-3.3.9-bin\apache-maven-3.3.9\repository</localRepository> | ||
+ | |||
+ | |||
+ | <!-- interactiveMode | ||
+ | | This will determine whether maven prompts you when it needs input. If set to false, | ||
+ | | maven will use a sensible default value, perhaps based on some other setting, for | ||
+ | | the parameter in question. | ||
+ | | | ||
+ | | Default: true | ||
+ | <interactiveMode>true</interactiveMode> | ||
+ | --> | ||
+ | |||
+ | <!-- offline | ||
+ | | Determines whether maven should attempt to connect to the network when executing a build. | ||
+ | | This will have an effect on artifact downloads, artifact deployment, and others. | ||
+ | | | ||
+ | | Default: false | ||
+ | <offline>false</offline> | ||
+ | --> | ||
+ | |||
+ | <!-- pluginGroups | ||
+ | | This is a list of additional group identifiers that will be searched when resolving plugins by their prefix, i.e. | ||
+ | | when invoking a command line like "mvn prefix:goal". Maven will automatically add the group identifiers | ||
+ | | "org.apache.maven.plugins" and "org.codehaus.mojo" if these are not already contained in the list. | ||
+ | |--> | ||
+ | <pluginGroups> | ||
+ | <!-- pluginGroup | ||
+ | | Specifies a further group identifier to use for plugin lookup. | ||
+ | <pluginGroup>com.your.plugins</pluginGroup> | ||
+ | --> | ||
+ | <pluginGroup>org.sonatype.plugins</pluginGroup> | ||
+ | <pluginGroup>org.sonarsource.scanner.maven</pluginGroup> | ||
+ | </pluginGroups> | ||
+ | |||
+ | <!-- proxies | ||
+ | | This is a list of proxies which can be used on this machine to connect to the network. | ||
+ | | Unless otherwise specified (by system property or command-line switch), the first proxy | ||
+ | | specification in this list marked as active will be used. | ||
+ | |--> | ||
+ | <proxies> | ||
+ | <!-- proxy | ||
+ | | Specification for one proxy, to be used in connecting to the network. | ||
+ | | | ||
+ | <proxy> | ||
+ | <id>optional</id> | ||
+ | <active>true</active> | ||
+ | <protocol>http</protocol> | ||
+ | <username>proxyuser</username> | ||
+ | <password>proxypass</password> | ||
+ | <host>proxy.host.net</host> | ||
+ | <port>80</port> | ||
+ | <nonProxyHosts>local.net|some.host.com</nonProxyHosts> | ||
+ | </proxy> | ||
+ | --> | ||
+ | </proxies> | ||
+ | |||
+ | <!-- servers | ||
+ | | This is a list of authentication profiles, keyed by the server-id used within the system. | ||
+ | | Authentication profiles can be used whenever maven must make a connection to a remote server. | ||
+ | |--> | ||
+ | <servers> | ||
+ | <!-- server | ||
+ | | Specifies the authentication information to use when connecting to a particular server, identified by | ||
+ | | a unique name within the system (referred to by the 'id' attribute below). | ||
+ | | | ||
+ | | NOTE: You should either specify username/password OR privateKey/passphrase, since these pairings are | ||
+ | | used together. | ||
+ | | --> | ||
+ | <server> | ||
+ | <id>nexus</id> | ||
+ | <username>admin</username> | ||
+ | <password>lxtxadmin123</password> | ||
+ | </server> | ||
+ | |||
+ | |||
+ | <!-- Another sample, using keys to authenticate. | ||
+ | <server> | ||
+ | <id>siteServer</id> | ||
+ | <privateKey>/path/to/private/key</privateKey> | ||
+ | <passphrase>optional; leave empty if not used.</passphrase> | ||
+ | </server> | ||
+ | --> | ||
+ | </servers> | ||
+ | |||
+ | <!-- mirrors | ||
+ | | This is a list of mirrors to be used in downloading artifacts from remote repositories. | ||
+ | | | ||
+ | | It works like this: a POM may declare a repository to use in resolving certain artifacts. | ||
+ | | However, this repository may have problems with heavy traffic at times, so people have mirrored | ||
+ | | it to several places. | ||
+ | | | ||
+ | | That repository definition will have a unique id, so we can create a mirror reference for that | ||
+ | | repository, to be used as an alternate download site. The mirror site will be the preferred | ||
+ | | server for that repository. | ||
+ | |--> | ||
+ | <mirrors> | ||
+ | <!-- mirror | ||
+ | | Specifies a repository mirror site to use instead of a given repository. The repository that | ||
+ | | this mirror serves has an ID that matches the mirrorOf element of this mirror. IDs are used | ||
+ | | for inheritance and direct lookup purposes, and must be unique across the set of mirrors. | ||
+ | | | ||
+ | <mirror> | ||
+ | <id>mirrorId</id> | ||
+ | <mirrorOf>repositoryId</mirrorOf> | ||
+ | <name>Human Readable Name for this Mirror.</name> | ||
+ | <url>http://my.repository.com/repo/path</url> | ||
+ | </mirror> | ||
+ | --> | ||
+ | <!-- | ||
+ | <mirror> | ||
+ | <id>nexus-aliyun</id> | ||
+ | <mirrorOf>central</mirrorOf> | ||
+ | <name>Nexus aliyun</name> | ||
+ | <url>http://maven.aliyun.com/nexus/content/groups/public</url> | ||
+ | </mirror> | ||
+ | |||
+ | <mirror> | ||
+ | <id>nexus-aliyun</id> | ||
+ | <mirrorOf>central</mirrorOf> | ||
+ | <name>Nexus aliyun</name> | ||
+ | <url>http://maven.aliyun.com/nexus/content/groups/public</url> | ||
+ | </mirror>--> | ||
+ | |||
+ | <mirror> | ||
+ | <id>nexus</id> | ||
+ | <mirrorOf>*</mirrorOf> | ||
+ | <url>http://192.168.4.189:8081/repository/maven-public/</url> | ||
+ | </mirror> | ||
+ | <!-- | ||
+ | <mirror> | ||
+ | <id>repo2</id> | ||
+ | <mirrorOf>central</mirrorOf> | ||
+ | <name>Human Readable Name for this Mirror.</name> | ||
+ | <url>http://repo2.maven.org/maven2/</url> | ||
+ | </mirror> --> | ||
+ | </mirrors> | ||
+ | |||
+ | <!-- profiles | ||
+ | | This is a list of profiles which can be activated in a variety of ways, and which can modify | ||
+ | | the build process. Profiles provided in the settings.xml are intended to provide local machine- | ||
+ | | specific paths and repository locations which allow the build to work in the local environment. | ||
+ | | | ||
+ | | For example, if you have an integration testing plugin - like cactus - that needs to know where | ||
+ | | your Tomcat instance is installed, you can provide a variable here such that the variable is | ||
+ | | dereferenced during the build process to configure the cactus plugin. | ||
+ | | | ||
+ | | As noted above, profiles can be activated in a variety of ways. One way - the activeProfiles | ||
+ | | section of this document (settings.xml) - will be discussed later. Another way essentially | ||
+ | | relies on the detection of a system property, either matching a particular value for the property, | ||
+ | | or merely testing its existence. Profiles can also be activated by JDK version prefix, where a | ||
+ | | value of '1.4' might activate a profile when the build is executed on a JDK version of '1.4.2_07'. | ||
+ | | Finally, the list of active profiles can be specified directly from the command line. | ||
+ | | | ||
+ | | NOTE: For profiles defined in the settings.xml, you are restricted to specifying only artifact | ||
+ | | repositories, plugin repositories, and free-form properties to be used as configuration | ||
+ | | variables for plugins in the POM. | ||
+ | | | ||
+ | |--> | ||
+ | <profiles> | ||
+ | <!-- profile | ||
+ | | Specifies a set of introductions to the build process, to be activated using one or more of the | ||
+ | | mechanisms described above. For inheritance purposes, and to activate profiles via <activatedProfiles/> | ||
+ | | or the command line, profiles have to have an ID that is unique. | ||
+ | | | ||
+ | | An encouraged best practice for profile identification is to use a consistent naming convention | ||
+ | | for profiles, such as 'env-dev', 'env-test', 'env-production', 'user-jdcasey', 'user-brett', etc. | ||
+ | | This will make it more intuitive to understand what the set of introduced profiles is attempting | ||
+ | | to accomplish, particularly when you only have a list of profile id's for debug. | ||
+ | | | ||
+ | | This profile example uses the JDK version to trigger activation, and provides a JDK-specific repo. | ||
+ | <profile> | ||
+ | <id>jdk-1.4</id> | ||
+ | |||
+ | <activation> | ||
+ | <jdk>1.4</jdk> | ||
+ | </activation> | ||
+ | |||
+ | <repositories> | ||
+ | <repository> | ||
+ | <id>jdk14</id> | ||
+ | <name>Repository for JDK 1.4 builds</name> | ||
+ | <url>http://www.myhost.com/maven/jdk14</url> | ||
+ | <layout>default</layout> | ||
+ | <snapshotPolicy>always</snapshotPolicy> | ||
+ | </repository> | ||
+ | </repositories> | ||
+ | </profile> | ||
+ | --> | ||
+ | |||
+ | <!-- | ||
+ | | Here is another profile, activated by the system property 'target-env' with a value of 'dev', | ||
+ | | which provides a specific path to the Tomcat instance. To use this, your plugin configuration | ||
+ | | might hypothetically look like: | ||
+ | | | ||
+ | | ... | ||
+ | | <plugin> | ||
+ | | <groupId>org.myco.myplugins</groupId> | ||
+ | | <artifactId>myplugin</artifactId> | ||
+ | | | ||
+ | | <configuration> | ||
+ | | <tomcatLocation>${tomcatPath}</tomcatLocation> | ||
+ | | </configuration> | ||
+ | | </plugin> | ||
+ | | ... | ||
+ | | | ||
+ | | NOTE: If you just wanted to inject this configuration whenever someone set 'target-env' to | ||
+ | | anything, you could just leave off the <value/> inside the activation-property. | ||
+ | | | ||
+ | <profile> | ||
+ | <id>env-dev</id> | ||
+ | |||
+ | <activation> | ||
+ | <property> | ||
+ | <name>target-env</name> | ||
+ | <value>dev</value> | ||
+ | </property> | ||
+ | </activation> | ||
+ | |||
+ | <properties> | ||
+ | <tomcatPath>/path/to/tomcat/instance</tomcatPath> | ||
+ | </properties> | ||
+ | </profile> | ||
+ | --> | ||
+ | <profile> | ||
+ | <id>nexus</id> | ||
+ | <repositories> | ||
+ | <repository> | ||
+ | <id>central</id> | ||
+ | <url>http://central</url> | ||
+ | <releases><enabled>true</enabled></releases> | ||
+ | <snapshots><enabled>true</enabled></snapshots> | ||
+ | </repository> | ||
+ | </repositories> | ||
+ | <pluginRepositories> | ||
+ | <pluginRepository> | ||
+ | <id>central</id> | ||
+ | <url>http://central</url> | ||
+ | <releases><enabled>true</enabled></releases> | ||
+ | <snapshots><enabled>true</enabled></snapshots> | ||
+ | </pluginRepository> | ||
+ | </pluginRepositories> | ||
+ | </profile> | ||
+ | </profiles> | ||
+ | |||
+ | <!-- activeProfiles | ||
+ | | List of profiles that are active for all builds. | ||
+ | | --> | ||
+ | <activeProfiles> | ||
+ | <activeProfile>nexus</activeProfile> | ||
+ | </activeProfiles> | ||
+ | |||
+ | </settings> | ||
+ | </pre> | ||
+ | |||
==[[Jenkins更多错误]]== | ==[[Jenkins更多错误]]== | ||
=进阶= | =进阶= | ||
+ | [[触发器之jenkins实现gitlab trigger]] | ||
+ | |||
+ | |||
[https://www.cnblogs.com/shenh/p/8963688.html jenkins + pipeline构建自动化部署] | [https://www.cnblogs.com/shenh/p/8963688.html jenkins + pipeline构建自动化部署] | ||
[https://blog.csdn.net/wh211212/article/details/77482138 Jenkins + Pipeline 构建流水线发布] | [https://blog.csdn.net/wh211212/article/details/77482138 Jenkins + Pipeline 构建流水线发布] | ||
+ | |||
+ | [https://www.jianshu.com/p/37dce9d1e10b Jenkins奇技淫巧] | ||
+ | |||
+ | [https://www.cnblogs.com/puresoul/p/4828913.html Jenkins内置环境变量的使用] | ||
+ | |||
+ | https://www.w3cschool.cn/jenkins/jenkins-5h3228n2.html | ||
+ | |||
=参考= | =参考= | ||
第364行: | 第1,042行: | ||
[https://blog.csdn.net/gbenson/article/details/50970289 Linux平台搭建Jenkins+Maven+Shell实现自动化构建部署] | [https://blog.csdn.net/gbenson/article/details/50970289 Linux平台搭建Jenkins+Maven+Shell实现自动化构建部署] | ||
+ | |||
+ | |||
+ | |||
+ | [https://www.jianshu.com/p/654505d42180 DevOps与CICD的区别 及 docker、k8s的CICD思路] | ||
+ | |||
==docker== | ==docker== | ||
第395行: | 第1,078行: | ||
[https://blog.csdn.net/qq_27791709/article/details/78835912 Jenkins-工作区清理插件] | [https://blog.csdn.net/qq_27791709/article/details/78835912 Jenkins-工作区清理插件] | ||
− | [[category:ops]] | + | |
+ | [https://www.jianshu.com/p/d6e9e63716a4 Jenkins常用插件全集] | ||
+ | |||
+ | [[category:ops]] [[category:devops]][[category:devops]] [[category:jenkins]] |
2024年8月30日 (五) 03:07的最新版本
仔细总结一下,我们会发现,除了编写代码,我们每天有相当一部分时间花在了编 译、运行单元测试、生成文档、打包和部署等烦琐且不起眼的工作上,这就是构建。如果我们现在还手工这样做,那成本也太高了,于是有人用软件的方法让这一系 列工作完全自动化,使得软件的构建可以像全自动流水线一样,只需要一条简单的命令,所有烦琐的步骤都能够自动完成,很快就能得到最终结果。
Maven真比自己的“规范化Ant”强大?其实他不知道自己只是在重新发明轮子,Maven已经有一大把现成的插件,全世界都在用,你自己不用写任何代码!
目录
see also
现在一般更新在 站内资源 如下 基于Docker的Jenkins持续集成
jenkins-cli
常用CI/CD CI, CD and CD
continuous[kənˈtɪnjuːəs] adj.连续的 deliver [dɪˈlɪvər] v.交付 continuous delivery, and continuous deployment.
CI, CD AND CD CI很容易理解,就是持续集成。但是CD既可以指代码持续交付(CONTINUOUS DELIVERY),也可理解为代码持续部署 (CONTINUOUS DEPLOYMENT)。CI和CD之间有很多相似的部分,但是也有很大的区别。
持续集成(CONTINUOUS INTEGRATION)
在持续集成环境中,开发人员将会频繁的提交代码到主干。这些新提交在最终合并到主线之前,都需要通过编译和自动化测试流进行验证。这样做是基于之前持续集成过程中很重视自动化测试验证结果,以保障所有的提交在合并主线之后的质量问题,对可能出现的一些问题进行预警。
持续交付(CONTINUOUS DELIVERY)
持续交付就是讲我们的应用发布出去的过程。这个过程可以确保我们尽可能快的实现交付。这就意味着除了自动化测试,我们还需要有自动化的发布流,以及通过一个按键就可以随时随地实现应用的部署上线。
通过持续交付,您可以决定每天,每周,每两周发布一次,这完全可以根据自己的业务进行设置。
但是,如果您真的希望体验持续交付的优势,就需要先进行小批量发布,尽快部署到生产线,以便在出现问题时方便进行故障排除。
持续部署(CONTINUOUS DEPLOYMENT)
如果我们想更加深入一步的话,就是持续部署了。通过这个方式,任何修改通过了所有已有的工作流就会直接和客户见面。没有人为干预(没有一键部署按钮),只有当一个修改在工作流中构建失败才能阻止它部署到产品线。
持续部署是一个很优秀的方式,可以加速与客户的反馈循环,但是会给团队带来压力,因为不再有“发布日”了。开发人员可以专注于构建软件,他们看到他们的修改在他们完成工作后几分钟就上线了。基本上,当开发人员在主分支中合并一个提交时,这个分支将被构建、测试,如果一切顺利,则部署到生产环境中。
CI 持续集成(Continuous
Integration)
CD 持续部署(Continuous Deployment 最最流行的,也是使用最多的Jenkins 有着持续集成DNA的ThoughtWorks GO。理念:"Deployment as pipeline" (华为容器平台应该是基于GO做的二次开发实现) Atlassian工具链之一的Bamboo 与Gitlab紧密集成的Gitlab CI 专为开源打造的Travis CI,与Github紧密集成 使用Python语言实现的Buildbot,相信Pythoner看到会喜欢
安装
通过docker-compose安装
apt install
#sep 2023 debian 11.0 只是感觉文档有点老 confused https://pkg.jenkins.io/debian-stable/ curl -fsSL https://pkg.jenkins.io/debian-stable/jenkins.io-2023.key | sudo tee \ /usr/share/keyrings/jenkins-keyring.asc > /dev/null echo deb [signed-by=/usr/share/keyrings/jenkins-keyring.asc] \ https://pkg.jenkins.io/debian-stable binary/ | sudo tee \ /etc/apt/sources.list.d/jenkins.list > /dev/null sudo apt-get update sudo apt-get install fontconfig openjdk-11-jre sudo apt-get install jenkins 正在读取状态信息... 完成 有 2157 个软件包可以升级。请执行 ‘apt list --upgradable’ 来查看它们。 W: https://pkg.jenkins.io/debian-stable/binary/Release.gpg: Key is stored in legacy trusted.gpg keyring (/etc/apt/trusted.gpg), see the DEPRECATION section in apt-key(8) for details. 重新导入一下 key root@myxps:/etc/apt/sources.list.d# curl -fsSL https://pkg.jenkins.io/debian-stable/jenkins.io.key | sudo tee \ /usr/share/keyrings/jenkins-keyring.asc > /dev/null #这样就更新为最新的lts sudo apt -y install jenkins
https://pkg.jenkins.io/debian-stable/
填写新仓库提示No ECDSA红字错误
我的jenkins是docker部署的 登录容器 apk add git 然后再把你的key 放入 并
需要在jenkins的容器里 执行以下命令访问git上的仓库地址,把git的主机添加到/root/.ssh/known_hosts(执行命令前known_hosts这个文件是不存在的,执行后就有了) https://blog.csdn.net/bigwood99/article/details/107073603
war 可以自定义目录
sudo apt install openjdk-11-jre sudo JENKINS_HOME=/home/evan/data/apps/war-jenkins/ java -jar /home/evan/data/apps/war-jenkins/jenkins.war #troubleshooting root@myxps:~# JENKINS_HOME=/home/evan/data/apps/war-jenkins/ java -jar /home/evan/data/apps/war-jenkins/jenkins.war Running with Java 8 from /usr/lib/jvm/java-8-openjdk-amd64/jre, which is older than the minimum required version (Java 11). Supported Java versions are: [11, 17] See https://jenkins.io/redirect/java-support/ for more information. ln -s /usr/lib/jvm/java-11-openjdk-amd64/bin/java /etc/alternatives/java
https://www.jenkins.io/doc/book/installing/war-file/
已放弃普通安装已放弃的方法
ip 192.168.0.16
已放弃 docker pull jenkins [root@localhost ~]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE jenkins latest cd14cecfdb3a 2 weeks ago 696MB docker run --name=jenkins -it -u root -d -p 8080:8080 -p 50000:50000 -v /data/jenkins:/var/jenkins_home cd14cecfdb3a --name=jenkins 命名 -it 交互模式运行 -u root root权限 -d 后台运行 -p 8080:8080 映射端口 -p 50000:50000 映射端口 -v /data/jenkins:/var/jenkins_home 映射目录 3f08dc4f3f5d 本地镜像ID docker images name 命令可查看ID eg #docker images jenkins #官方 mkdir -p /data/jenkins-data docker run \ --name=jenkins \ -u root \ --rm \ -d \ -p 8080:8080 \ -p 50000:50000 \ -v /data/jenkins-data:/var/jenkins_home \ -v /var/run/docker.sock:/var/run/docker.sock \ jenkinsci/blueocean #在运行docker容器时可以加如下参数来保证每次docker服务重启后容器也自动重启: $docker run --restart=always #如果已经启动了则可以使用如下命令: $docker update --restart=always <CONTAINER ID> 登入容器: docker exec -it jenkins /bin/bash 同步容器时间 在Dockerfile中加入 RUN cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && ntpdate cn.pool.ntp.org 或 容器运行后把容主机的/usr/share/zoneinfo/Asia/Shanghai 复制到容器的/etc/localtime #先cp 到 /data/jenkins cp /usr/share/zoneinfo/Asia/Shanghai /data/jenkins plubs Publish Over SSH Maven Integration Build clean install
http://cn.jenkins.io/doc/book/installing/
安装请见 Docker入门
jenkins使用
要先安装maven 什么的 Build Root POM pom.xml Goals and options clean install Post Steps Ex shell cd /var/jenkins_home/workspace/doll-api-test/target scp doll-api-test.jar [email protected]:/data/update/boot/doll-api sen build aritcle ex command #记得要要全局那加ssh server
jenkins slave
k8s 创建jenkins slave Pod节点 详情参考 How to Setup Jenkins Build Agents on Kubernetes Pods
选择一个或多个节点作为k8s 创建jenkins slave Pod的节点 配置参考可见此url https://github.com/sunweisheng/Jenkins/blob/master/Jenkins-Kubernetes.md 创建一个流水线 job #内容差不多这样 podTemplate { node(POD_LABEL) { stage('echo something') { sh 'echo hello world from pod test ' } } } 运动成功的结果 差不多这些 tarted by user evan [Pipeline] Start of Pipeline [Pipeline] podTemplate [Pipeline] { [Pipeline] node Created Pod: kubernetes-study default/testoct23pm-2-bfcr1-fzhwb-cklsv Still waiting to schedule task Waiting for next available executor on ‘testoct23pm-2-bfcr1-fzhwb-cklsv’ 代理 testoct23pm-2-bfcr1-fzhwb-cklsv 由模板 testoct23pm_2-bfcr1-fzhwb 提供 --- apiVersion: "v1" kind: "Pod" metadata: annotations: buildUrl: "http://192.168.10.105:8080/job/testoct23pm/2/" runUrl: "job/testoct23pm/2/" labels: jenkins: "slave" jenkins/label-digest: "a0fe9942b760b4677c42994a4fde67d00032b3df" jenkins/label: "testoct23pm_2-bfcr1" name: "testoct23pm-2-bfcr1-fzhwb-cklsv" namespace: "default" Running on testoct23pm-2-bfcr1-fzhwb-cklsv in /home/jenkins/agent/workspace/testoct23pm [Pipeline] { [Pipeline] stage [Pipeline] { (echo something) [Pipeline] sh + echo hello world from pod test hello world from pod test [Pipeline] } [Pipeline] // stage [Pipeline] } [Pipeline] // node [Pipeline] } [Pipeline] // podTemplate [Pipeline] End of Pipeline Finished: SUCCESS or Started by user evan [Pipeline] Start of Pipeline [Pipeline] podTemplate [Pipeline] { [Pipeline] node Created Pod: kubernetes-study default/testoct23pm-1-v6jx5-brq84-ns0x8 Still waiting to schedule task ‘testoct23pm-1-v6jx5-brq84-ns0x8’ is offline 代理 testoct23pm-1-v6jx5-brq84-ns0x8 由模板 testoct23pm_1-v6jx5-brq84 提供 --- apiVersion: "v1" kind: "Pod" eg2 podTemplate(label: 'build', containers: [ containerTemplate(name: 'docker', image: 'docker', command: 'cat', ttyEnabled: true) ], volumes: [ hostPathVolume(mountPath: '/var/run/docker.sock', hostPath: '/var/run/docker.sock'), ] ) { node('build') { container('docker') { sh 'hostname' sh 'ip a' } } }
普通jenkins slave
sudo java -jar agent.jar -jnlpUrl http://192.168.10.105:8080/computer/jenkins%2Dslave1/jenkins-agent.jnlp -secret d3978968148304770e0ecf18f8dd6e18ed61580afde6086ea03113c997fc35bf -workDir "/tmp/jenkins" 问题 jenkins slave ava.lang.Exception: The server rejected the connection: None of the protocols are enabled Jenkins -> Global Security Configuration -> Agents -> Agent protocols -> Inbound TCP Agent Protocol/4 (TLS encryption) 代理 指定端口 50000 代理协议 Java Web Start Agent Protocol/4 (TLS 加密)
gradle
Gradle是一个基于Apache Ant和Apache Maven概念的项目自动化建构工具。它使用一种基于Groovy的特定领域语言来声明项目设置,而不是传统的XML。 当前其支持的语言限于Java、Groovy和Scala,计划未来将支持更多的语言。
和maven同级,更简洁一些
https://docs.gradle.org/current/userguide/userguide.html
maven
我试过 好像不用安装 jdk的呀 docker化的jenkins 安装在configureTools 全局配置那里 要加上maven 和填写版本 以这个为目录名 例如下面的maven3.6.2 Build->Goals and options ->clean install -Pbeta -Dmaven.test.skip=true
Jenkins部署Maven多环境项目(dev、beta、prod)的参数设置
maven 配置文件
maven 配置 可以在母机修改 注意 要先至少跑个工程后 才会安装maven 生成这个目录了 有时要密码的 ,格式要小心 烦死了 /data/docker/volumes/docker4jenkins_jenkins_home/_data/tools/hudson.tasks.Maven_MavenInstallation/maven/conf/settings.xml /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 位置 153 <mirror> 154 <id>mirrorId</id> 155 <mirrorOf>repositoryId</mirrorOf> 156 <name>Human Readable Name for this Mirror.</name> 157 <url>http://my.repository.com/repo/path</url> 158 </mirror> 159 --> 160 <mirror> 161 <id>nexus</id> 162 <mirrorOf>*</mirrorOf> 163 <url>http://192.168.4.189:8081/repository/maven-public/</url> 164 </mirror> 165 </mirrors> 公用的方便安装的如下配置 <mirrors> <!-- mirror | Specifies a repository mirror site to use instead of a given repository. The repository that | this mirror serves has an ID that matches the mirrorOf element of this mirror. IDs are used | for inheritance and direct lookup purposes, and must be unique across the set of mirrors. | <mirror> <id>mirrorId</id> <mirrorOf>repositoryId</mirrorOf> <name>Human Readable Name for this Mirror.</name> <url>http://my.repository.com/repo/path</url> </mirror> --> <mirror> <id>alimaven</id> <name>aliyun maven</name> <url>http://maven.aliyun.com/nexus/content/groups/public/</url> <mirrorOf>central</mirrorOf> </mirror> </mirrors> #lx <servers> <server> <id>nexus</id> <username>admin</username> <password>lxtxadmin123</password> </server> </servers> <mirrors> <mirror> <id>nexus</id> <mirrorOf>*</mirrorOf> <url>http://192.168.4.189:8081/repository/maven-public/</url> </mirror> <!-- <mirror>--> <!-- <id>nexus-aliyun</id>--> <!-- <mirrorOf>central</mirrorOf>--> <!-- <name>Nexus aliyun</name>--> <!-- <url>http://maven.aliyun.com/nexus/content/groups/public</url>--> <!-- </mirror>--> </mirrors>
Maven国内可用下载速度快的仓库镜像(阿里Maven镜像地址)
snapshot快照仓库和release发布仓库
maven中的仓库分为两种,snapshot快照仓库和release发布仓库。snapshot快照仓库用于保存开发过程中的不稳定版 本,release正式仓库则是用来保存稳定的发行版本。定义一个组件/模块为快照版本,只需要在pom文件中在该模块的版本号后加上-SNAPSHOT即可(注意这里必须是大写)。release版本不允许修改,每次进行release版本修改,发布必须提升版本号。而snapshot一般是开发过程中的迭代版本,snapshot更新后,引用的项目可以不修改版本号自动下载构建。
MAVEN snapshot快照和release发布库的区别、作用
git branch
这里应该 填写上操作过程 在我的geany上
goodJenkins Git Parameter 插件配置过程
Jenkins:使用Git Parameter插件实现tag或分支的选择性构建
jenkins插件Git Parameter Plug-In分支构建项目
android
[ https://blog.csdn.net/youshi520000/article/details/81027940 Android 使用 Jenkins 实现自动化打包【流程】&【踩坑]
Jenkins的初级应用(2)-Invoke Phing targets
Jenkins的初级应用(2)-Invoke Phing targets
启动
supervisor
#配合supervisor,把Jenkins直接变成一个服务。 #可以在Linux上创建一个ci用户,然后,用supervisor启动并指定9090端口: # /etc/supervisor/conf.d/ci.conf [program:ci] command=java -jar /home/ci/jenkins.war --httpPort=9090 user=ci autostart=true autorestart=true startsecs=30 startretries=5
权限控制
Role-based Authorization Strategy
可选插件-->Role-based Authorization Strategy
超级用户 root root
other evan
group ops java admin
基于项目(job)
--> Manage Roles Project roles 创建一个 dev 只配置所以 dev开头的内网项目 Role to add dev Pattern dev.* #配置 选择【 Manage Roles】 在【Global roles】创建一个新的全局角色 anyone,该角色不开放系统权限,只读. 然后把你的号添加到 Global roles Assign Roles-- Item roles 里面 加入你的号 并勾上 dev 注意: Global roles 必要有 你要给别人用的用户名,不登录了什么 都没提示全局没有读权限
godd lxtx eg
2021年 11月 17日 星期三 19:46:26 这个不错 不过还要用视图,不要让见到太多 pre 倒好这里有个前端小哥 就叫 wusiyi Manage Roles 角色管理 -- Global roles: Role to add role name 为desk 全给read Item roles : role to add :Frontend_h5 Pattern: (?i)stage-.*|prod-hailuo-sdk-doc|bcb-blockchain-h5|k8s-local-nuxt-snsdev-hailuo-open-website 这个权限就看你给了 Assign Roles分配角色 Global roles: wusiyi 选择在 desk ; Item roles:Frontend_h5 和上面的 role to add 对应
权限see also
Jenkins教程四基于Role-based Authorization Strategy的用户权限管理
enkins教程四 基于【Role-based Authorization Strategy】的用户权限管理
jenkins Manage and Assign Roles使用
插件
dashboard 插件
dashboard 插件 Dashboard View 用来自定义自己的主页,例如对下列的 jenkins 的主页
Wall display
用来将 jobs 的状态更加直观地显示在大屏幕上
国内的源:https://mirrors.tuna.tsinghua.edu.cn/jenkins/plugins/
ssh server
troubleshooting
jenkins.plugins.publish_over.BapPublisherException: Failed to connect and initialize SSH connection. Message: [Failed to connect session for config [win8r2]. Message [USERAUTH fail]] 在jenkins 上使用publish over ssh ,报上述错误, ssh server 1. 配置里面添加 jenkins pri key 2.远程被 jenkins 的远程那里添加jenkin的pub key
https://ask.csdn.net/questions/379784
NODE
jenkins plugin 要安装 node
apk add --no-cache python
alpine 里面也要安装 node.js alpine https://wiki.linuxchina.net/index.php/Alpine#docker
php jenkins 实现PHP持续集成部署
xk
dev 开发环境 beta 测试环境 release 正式环境
DB
磁盘处理
trouble shooting
WeChat.java:[266,43] 找不到符号
[ERROR] /root/.jenkins/workspace/release_read/xtwl_service/src/main/java/org/platform_service/universal/pay/WeChat.java:[266,43] 找不到符号 Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project xtwl_service: Compilation failure 原来是我用了 clean package -Prelease 之前还替换了配置文件 哈哈
offline
点击Continue,大部分人都会出现这个界面,毕竟在天朝,我们先选择跳过
project lxtx-hello-admin-dao: Could not resolve dependencies for project com.lxtx.hello:lxtx
Waiting for Jenkins to finish collecting data [ERROR] Failed to execute goal on project lxtx-hello-admin-dao: Could not resolve dependencies for project com.lxtx.hello:lxtx-hello-admin-dao:jar:0.0.1: Could not find artifact com.lxtx.im:lxtx-admin-base-service:jar:0.1.6 in central (https://repo.maven.apache.org/maven2) -> [Help 1] [ERROR] [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch. [ERROR] Re-run Maven using the -X switch to enable full debug logging. [ERROR] [ERROR] For more information about the errors and possible solutions, please read the following articles: [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/DependencyResolutionException [ERROR] [ERROR] After correcting the problems, you can resume the build with the command [ERROR] mvn <goals> -rf :lxtx-hello-admin-dao
soult
docker dir /var/jenkins_home/.m2/settings.xml 母鸡目录 /volumes/docker4jenkins_jenkins_home/_data/.m2/settings.xml <?xml version="1.0" encoding="UTF-8"?> <!-- Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. --> <!-- | This is the configuration file for Maven. It can be specified at two levels: | | 1. User Level. This settings.xml file provides configuration for a single user, | and is normally provided in ${user.home}/.m2/settings.xml. | | NOTE: This location can be overridden with the CLI option: | | -s /path/to/user/settings.xml | | 2. Global Level. This settings.xml file provides configuration for all Maven | users on a machine (assuming they're all using the same Maven | installation). It's normally provided in | ${maven.home}/conf/settings.xml. | | NOTE: This location can be overridden with the CLI option: | | -gs /path/to/global/settings.xml | | The sections in this sample file are intended to give you a running start at | getting the most out of your Maven installation. Where appropriate, the default | values (values used when the setting is not specified) are provided. | |--> <settings xmlns="http://maven.apache.org/SETTINGS/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd"> <!-- localRepository | The path to the local repository maven will use to store artifacts. | | Default: ${user.home}/.m2/repository --> <localRepository>D:\tools\apache-maven-3.3.9-bin\apache-maven-3.3.9\repository</localRepository> <!-- interactiveMode | This will determine whether maven prompts you when it needs input. If set to false, | maven will use a sensible default value, perhaps based on some other setting, for | the parameter in question. | | Default: true <interactiveMode>true</interactiveMode> --> <!-- offline | Determines whether maven should attempt to connect to the network when executing a build. | This will have an effect on artifact downloads, artifact deployment, and others. | | Default: false <offline>false</offline> --> <!-- pluginGroups | This is a list of additional group identifiers that will be searched when resolving plugins by their prefix, i.e. | when invoking a command line like "mvn prefix:goal". Maven will automatically add the group identifiers | "org.apache.maven.plugins" and "org.codehaus.mojo" if these are not already contained in the list. |--> <pluginGroups> <!-- pluginGroup | Specifies a further group identifier to use for plugin lookup. <pluginGroup>com.your.plugins</pluginGroup> --> <pluginGroup>org.sonatype.plugins</pluginGroup> <pluginGroup>org.sonarsource.scanner.maven</pluginGroup> </pluginGroups> <!-- proxies | This is a list of proxies which can be used on this machine to connect to the network. | Unless otherwise specified (by system property or command-line switch), the first proxy | specification in this list marked as active will be used. |--> <proxies> <!-- proxy | Specification for one proxy, to be used in connecting to the network. | <proxy> <id>optional</id> <active>true</active> <protocol>http</protocol> <username>proxyuser</username> <password>proxypass</password> <host>proxy.host.net</host> <port>80</port> <nonProxyHosts>local.net|some.host.com</nonProxyHosts> </proxy> --> </proxies> <!-- servers | This is a list of authentication profiles, keyed by the server-id used within the system. | Authentication profiles can be used whenever maven must make a connection to a remote server. |--> <servers> <!-- server | Specifies the authentication information to use when connecting to a particular server, identified by | a unique name within the system (referred to by the 'id' attribute below). | | NOTE: You should either specify username/password OR privateKey/passphrase, since these pairings are | used together. | --> <server> <id>nexus</id> <username>admin</username> <password>lxtxadmin123</password> </server> <!-- Another sample, using keys to authenticate. <server> <id>siteServer</id> <privateKey>/path/to/private/key</privateKey> <passphrase>optional; leave empty if not used.</passphrase> </server> --> </servers> <!-- mirrors | This is a list of mirrors to be used in downloading artifacts from remote repositories. | | It works like this: a POM may declare a repository to use in resolving certain artifacts. | However, this repository may have problems with heavy traffic at times, so people have mirrored | it to several places. | | That repository definition will have a unique id, so we can create a mirror reference for that | repository, to be used as an alternate download site. The mirror site will be the preferred | server for that repository. |--> <mirrors> <!-- mirror | Specifies a repository mirror site to use instead of a given repository. The repository that | this mirror serves has an ID that matches the mirrorOf element of this mirror. IDs are used | for inheritance and direct lookup purposes, and must be unique across the set of mirrors. | <mirror> <id>mirrorId</id> <mirrorOf>repositoryId</mirrorOf> <name>Human Readable Name for this Mirror.</name> <url>http://my.repository.com/repo/path</url> </mirror> --> <!-- <mirror> <id>nexus-aliyun</id> <mirrorOf>central</mirrorOf> <name>Nexus aliyun</name> <url>http://maven.aliyun.com/nexus/content/groups/public</url> </mirror> <mirror> <id>nexus-aliyun</id> <mirrorOf>central</mirrorOf> <name>Nexus aliyun</name> <url>http://maven.aliyun.com/nexus/content/groups/public</url> </mirror>--> <mirror> <id>nexus</id> <mirrorOf>*</mirrorOf> <url>http://192.168.4.189:8081/repository/maven-public/</url> </mirror> <!-- <mirror> <id>repo2</id> <mirrorOf>central</mirrorOf> <name>Human Readable Name for this Mirror.</name> <url>http://repo2.maven.org/maven2/</url> </mirror> --> </mirrors> <!-- profiles | This is a list of profiles which can be activated in a variety of ways, and which can modify | the build process. Profiles provided in the settings.xml are intended to provide local machine- | specific paths and repository locations which allow the build to work in the local environment. | | For example, if you have an integration testing plugin - like cactus - that needs to know where | your Tomcat instance is installed, you can provide a variable here such that the variable is | dereferenced during the build process to configure the cactus plugin. | | As noted above, profiles can be activated in a variety of ways. One way - the activeProfiles | section of this document (settings.xml) - will be discussed later. Another way essentially | relies on the detection of a system property, either matching a particular value for the property, | or merely testing its existence. Profiles can also be activated by JDK version prefix, where a | value of '1.4' might activate a profile when the build is executed on a JDK version of '1.4.2_07'. | Finally, the list of active profiles can be specified directly from the command line. | | NOTE: For profiles defined in the settings.xml, you are restricted to specifying only artifact | repositories, plugin repositories, and free-form properties to be used as configuration | variables for plugins in the POM. | |--> <profiles> <!-- profile | Specifies a set of introductions to the build process, to be activated using one or more of the | mechanisms described above. For inheritance purposes, and to activate profiles via <activatedProfiles/> | or the command line, profiles have to have an ID that is unique. | | An encouraged best practice for profile identification is to use a consistent naming convention | for profiles, such as 'env-dev', 'env-test', 'env-production', 'user-jdcasey', 'user-brett', etc. | This will make it more intuitive to understand what the set of introduced profiles is attempting | to accomplish, particularly when you only have a list of profile id's for debug. | | This profile example uses the JDK version to trigger activation, and provides a JDK-specific repo. <profile> <id>jdk-1.4</id> <activation> <jdk>1.4</jdk> </activation> <repositories> <repository> <id>jdk14</id> <name>Repository for JDK 1.4 builds</name> <url>http://www.myhost.com/maven/jdk14</url> <layout>default</layout> <snapshotPolicy>always</snapshotPolicy> </repository> </repositories> </profile> --> <!-- | Here is another profile, activated by the system property 'target-env' with a value of 'dev', | which provides a specific path to the Tomcat instance. To use this, your plugin configuration | might hypothetically look like: | | ... | <plugin> | <groupId>org.myco.myplugins</groupId> | <artifactId>myplugin</artifactId> | | <configuration> | <tomcatLocation>${tomcatPath}</tomcatLocation> | </configuration> | </plugin> | ... | | NOTE: If you just wanted to inject this configuration whenever someone set 'target-env' to | anything, you could just leave off the <value/> inside the activation-property. | <profile> <id>env-dev</id> <activation> <property> <name>target-env</name> <value>dev</value> </property> </activation> <properties> <tomcatPath>/path/to/tomcat/instance</tomcatPath> </properties> </profile> --> <profile> <id>nexus</id> <repositories> <repository> <id>central</id> <url>http://central</url> <releases><enabled>true</enabled></releases> <snapshots><enabled>true</enabled></snapshots> </repository> </repositories> <pluginRepositories> <pluginRepository> <id>central</id> <url>http://central</url> <releases><enabled>true</enabled></releases> <snapshots><enabled>true</enabled></snapshots> </pluginRepository> </pluginRepositories> </profile> </profiles> <!-- activeProfiles | List of profiles that are active for all builds. | --> <activeProfiles> <activeProfile>nexus</activeProfile> </activeProfiles> </settings>
Jenkins更多错误
进阶
https://www.w3cschool.cn/jenkins/jenkins-5h3228n2.html
参考
Gradle是一个基于Apache Ant和Apache Maven概念的项目自动化建构工具
Jenkins学习之自动构建部署maven项目 have emailetc
学习maven的使用,看到一篇很实用的入门教程(菜鸟级入门)
Jenkins 持续集成平台构建之使用nexus搭建maven私有仓库
Jenkins之配置Maven和JDK-yellowcong
基于Linux实现Jenkins+maven+git+tomcat的自动化构建部署项目
Linux平台搭建Jenkins+Maven+Shell实现自动化构建部署
DevOps与CICD的区别 及 docker、k8s的CICD思路
docker
Jenkins Docker安装及Docker build step插件部署配置
原创:jenkins+github+docker+maven自动化构建部署
权限
Jenkins进阶系列之——14配置Jenkins用户和权限
maven
Jenkins部署Maven多环境项目(dev、beta、prod)的参数设置
通过Maven和Jenkins插件解决Java项目的配置管理