Jenkins流水线项目发布流程
Posted 包子的博客
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Jenkins流水线项目发布流程相关的知识,希望对你有一定的参考价值。
Jenkins流水线项目发布流程
本次环境为:
主机名 | IP地址 | 安装的应用 | 系统版本 |
---|---|---|---|
jenkins | 192.168.100.1 | tomcat jenkins | RedHat 8 |
tomcat、jenkins安装配置步骤请见:Jenkins配置
准备工作:
[root@jenkins ~]# systemctl disable --now firewalld
[root@jenkins ~]# sed -i "s/SELINUX=enforcing/SELINUX=disabled/g" /etc/selinux/config
[root@jenkins ~]# setenforce 0
[root@jenkins ~]# yum -y install maven git
安装Pipeline、Publish Over SSH、Publish Over SSH、SSH Build Agents、Git、GitHub、GitLab、Gitee插件(出现错误多装几次)
Gitee配置公钥
//创建密钥
[root@jenkins ~]# ssh-keygen -t rsa -b 2048 -C "qinghao_yu@163.com" -N "" -f /root/.ssh/id_rsa
Generating public/private rsa key pair.
Created directory \'/root/.ssh\'.
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:MtYf5/dFCJuwZ37E4sO3as6b5r0i3xbdoArF1ABiQv8 qinghao_yu@163.com
The key\'s randomart image is:
+---[RSA 2048]----+
| .o o ...o |
| + . . . |
| . o. . |
| o oo =.. |
| + E.o B.+oo|
| . o.. X.o..o|
| ...* +..|
| o.+O.o.|
| BO==..|
+----[SHA256]-----+
//查看公钥
[root@jenkins ~]# cat /root/.ssh/id_rsa.pub
ssh-rsa ······nK6lb5w5oe2fkbMcVSsMksFwDC/cZ7LC7uWuBpS9YoKOgzAqtxoK30UJP1FQlDm/chzZNnxgnuCFUD/ppcCONLHHmuWotonj4bDVl/KjfpDfiq6srkceVr3cBEdadj5nD2NO+udmnmvzBxXFruaubm/7LBq64DVnODEbPs8q/FQM09wp8Cjk5ephdqdkyiUIyQP qinghao_yu@163.com
登录Gitee然后将公钥复制进去
Jenkins 创建凭据
选择ssh username with private key类型(Jenkins要为最新版) —— 添加私钥
//查看私钥
[root@jenkins ~]# cat /root/.ssh/id_rsa
-----BEGIN OPENSSH PRIVATE KEY-----
······
HmuWotonj4bDVl/KjfpDfiq6srkceVr3cBEdadj5nD2NO+udmnmvzBxXFruaubm/7LBq64
DVnODEbPs8q/FQM09wp8Cjk5ephdqdkyiUIyQPAAAAAwEAAQAAAQEAttAv7CgVzBpdYyyN
O0Lkzo0W/vmEtkI+O7kThleV9OBao8usZShckZyprJp0S376JG9W/ipG2FvF583ipR+Ulf
gv2xN+GFus0iWYHb3rP3EUtyarWrQZnNLHeFYLunRfp9dTfSDqpZ+I0t1s8QvpoXAkkgUo
vMWrTe6U5R91bhtgTOYrfViARpu+91UQrPA98jnCqQn2wI7RgUqlyO/Th1i1Q9tIw7WQ0Z
NCf0cRbQRUVGv3m/UtPLNokt1aXbH6qdpRlpZBp2behm3TYGxBxt9ieC/lmp97dmZQP45w
tBbR6FHfjfI0Doi5q6d8LCQRqFEHug2v2yDtSvuzKRYj4QAAAIAoeQxB8kpJPiR0yMvfNM
goFN4D/clrmrek5O8WFMNnd/yeLrHJGZQ1maiTB0v6cV0NtzbGb+ngst56jnj+tr9CM463
DYaUqIcesz/AqIkPpJeQmKATPKxY9OC3b+CcHGcuK+iFTU4nnsXfQWAaqxrEhs1gydfNSW
YT3+CPb6HmGQAAAIEA94veCz56oMtcFgOvW1QNlqUkb3OlVDRiajDHmoV8/dkRd5WHfSVd
j4bXEUlUlybs3pjTRvlRponQ0GobrzTP4mvPpTpahTlNrQIpICPwdaYD/jkK0AC1rQ5bS2
sEFD14o8OhoGa2E82WIr+sVjKM0tlJh0ncJGqd9aFAk23LEDcAAACBAN+sdj81xrcRXWob
EfqJGeXHHtiHgrtFBIzGnduthLCUJn97IrnSV0Tj+0AE6o1CKrko4ZuOFjMuGpFfN62sjC
yw8w1MVMG7xAfkvJiRDbetPeRa8mfMXTKiBPi5Bx8NDW9ctXSDomv8ChP25b7CEh71imLk
ZkLbAVQ0ooYLFK7pAAAAEnFpbmdoYW9feXVAMTYzLmNvbQ==
-----END OPENSSH PRIVATE KEY-----
添加成功
Jenkins 配置流水线
创建项目
生成流水线脚本
配置流水线
pipeline {
agent any
stages {
stage(\'拉代码\') {
steps {
checkout([$class: \'GitSCM\', branches: [[name: \'*/master\']], extensions: [], userRemoteConfigs: [[credentialsId: \'3272aa67-1fb3-4334-a85a-b8a633838613\', url: \'https://gitee.com/xiaoming_de/my-tomcat.git\']]])
}
}
stage(\'打包\') {
steps {
sh "mvn clean package -Dmaven.test.skip=true"
sh "export BUILD_ID=\'dontKillMe\'"
sh "JENKINS_NODE_COOKIE=dontKillMe nohup java -jar /opt/test-boot-0.0.1-SNAPSHOT.jar &"
}
}
}
}
构建失败
以上是关于Jenkins流水线项目发布流程的主要内容,如果未能解决你的问题,请参考以下文章