【开发工具】Jenkins+Gitlab实现自动化部署

更新时间:2023-07-12 19:21:34 阅读: 评论:0

【开发⼯具】Jenkins+Gitlab实现⾃动化部署
我在尝试在容器中安装Jenkins时,初衷是希望使⽤docker in docker 的模式来实现Jenkins slave容器按需创建。在实现的时候需要在Jenkins 中安装Kubernetes插件。
kubernetes的插件⽬前来看存在⼀个Bug,这个bug很⼩但是会导致我们⽆法设置和kubernetes mastert认证的机制。Bug是由于配置代理时候是⽤的IP 地址,但是jenkins必须加⼊http协议,可惜的是加⼊http协议后更新的代理⼜不能使⽤了,进⼊这种死循环了。所以这种⽅案暂时搁置。
我在写这篇⽂章的时候,Jenkins X 还没有出来。。。⽬前Jenkins 是拥抱了K8S;我认为CI CD环境容器化编排是⼤趋势。
⼀些实践
搭建过基于K8S的完整的平台,写了系列的⽂章总结。有些⼩的团队或者独⽴开发者,单独⼀个Jenkins和Gitlab就⾜够做编译⾃动化了。
So,这⾥我会写常⽤的实现⾃动化部署的⽅案之Jenkins+Gitlab这种模式,在⼩型的开发时候完全够⽤了,从来没有⼀致的最佳⽅案,只有适不适合咱们的团队⽅案。
Jenkins的安装 - 官⽹
To u this repository, run the following command:
sudo wget -O /pos.po pkg.jenkins.io/po
sudo rpm --import pkg.jenkins.io/redhat-stable/jenkins.io.key
If you've previously imported the key from Jenkins, the "rpm --import" will fail becau you already have a key. Plea ignore that and move on.
You will need to explicitly install a Java runtime environment, becau Oracle's Java RPMs are incorrect and fail to register as providing a java dependency. Thus, adding an explicit dependency requirement on Java would force installation of the OpenJDK JVM.
2.54 (2017-04) and newer: Java 8
1.612 (2015-05) and newer: Java 7
With that t up, the Jenkins package can be installed with:
yum install jenkins
See Wiki for more information, including how Jenkins is run and where the configuration is stored, etc.
Gitlab的安装
⾃⼰⽹上找吧,但是安装8.0+的版本,因为后⾯webhooks是有版本的要求的。
⾃动化部署配置
创建普通编译Job
Jenkins创建⼀个Job,并配置git信息
注意,这⾥连接Gitlab需要配置认证
frosted同时,保证jenkins机器安装了Java, maven。
Maven 中需要配置成我们⾃⼰的仓库,配置即可。
[root@jenkins ~]# find / -l
/etc/l
/var/lib/jenkins/.l
/usr/share/maven/l
[root@jenkins ~]# cat /usr/share/maven/l
更改成公司artificatory配置
<mirror>
<id>mirrorId_2</id>
<mirrorOf>*</mirrorOf>
<name>Human Readable Name for this Mirror.</name>
<url>/nexus/content/groups/public/</url>
</mirror>-->
<mirror>
<id>mirrorId_1</id>
<mirrorOf>*</mirrorOf>
<name>Human Readable Name for this Mirror.</name>
<url>your_ip:your_port/artifactory/list/maven2/</url>
高考后出国留学
</mirror>
加⼊CI Trigger功能
Jenkins Trigger配置
Gitlab配置webhook
测试webhook:
加⼊CD功能
⾃动化运⾏脚本编写
[root@jenkins ~]# cat run.sh
#!/bin/bash
echo 'Checking scic document '
SCIC_APP_PID=$(ps -ef | grep scic_paas_doc | grep -v grep | awk '{ print $2 }')
if [ -z "$SCIC_APP_PID" ]
then
echo Starting
nohup java -jar scic_paas_doc-0.0.1-RELEASE.jar > doc.log 2>&1 &
echo Started successfully.
el
echo killing old rvice -  $SCIC_APP_PID ...
kill $SCIC_APP_PID
echo Restarting
nohup java -jar scic_paas_doc-0.0.1-RELEASE.jar > doc.log 2>&1 &
echo Restarted successfully.
fi
Global配置SSH Server
Build Job中配置PostBuild,Over SSH
通过SSH上传jar,并使⽤脚本运⾏
更新并提交代码
Z003MRZB@AAECNSHA02921L MINGW64 /d/git/k8s/scic_paas_doc (master)
decline用法>timber
$ git add .
sobeautiful
warning: LF will be replaced by CRLF in src/main/resources/static/_sidebar.md.
The file will have its original line endings in your working directory.
Z003MRZB@AAECNSHA02921L MINGW64 /d/git/k8s/scic_paas_doc (master)
$ git commit
warning: LF will be replaced by CRLF in src/main/resources/static/_sidebar.md.
The file will have its original line endings in your working directory.
[master warning: LF will be replaced by CRLF in src/main/resources/static/_sidebar.md.
mistakesThe file will have its original line endings in your working directory.
50c1cc4] test trigger
warning: LF will be replaced by CRLF in src/main/resources/static/_sidebar.md.
The file will have its original line endings in your working directory.
1 file changed, 1 inrtion(+), 1 deletion(-)
Z003MRZB@AAECNSHA02921L MINGW64 /d/git/k8s/scic_paas_doc (master)
$ git push
Counting objects: 7, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (6/6), done.
Writing objects: 100% (7/7), 499 bytes | 0 bytes/s, done.
Total 7 (delta 5), reud 0 (delta 0)
To git@10.192.29.91:k8s_test/scic_paas_doc.git
63b8ff4..50c1cc4  master -> master
触发编译和⾃动化部署
Tigger Build Logs
Started by GitLab push by daipeng
Building in workspace /var/lib/jenkins/workspace/SCIC_DOC_TRIGGER_BUILD
> git rev-par --is-inside-work-tree # timeout=10
Fetching changes from the remote Git repository
> git igin.url git@10.192.29.91:k8s_test/scic_paas_doc.git # timeout=10
Fetching upstream changes from git@10.192.29.91:k8s_test/scic_paas_doc.git
> git --version # timeout=10
using GIT_SSH to t credentials jenkins master rver key
> git fetch --tags --progress git@10.192.29.91:k8s_test/scic_paas_doc.git +refs/heads/*:refs/remotes/origin/* > git rev-par remotes/origin/master^{commit} # timeout=10
> git branch -a -v --no-abbrev --contains 50c1cc4499394d70919a470db5961cec00e65457 # timeout=10 Checking out Revision 50c1cc4499394d70919a470db5961cec00e65457 (origin/master)
Commit message: "test trigger"
> git config core.sparcheckout # timeout=10
> git checkout -f 50c1cc4499394d70919a470db5961cec00e65457
鹤立鸡群是什么意思> git rev-list 99d919b08d5a2010fe750d4d920a10024401bc92 # timeout=102014高考成绩查询
[SCIC_DOC_TRIGGER_BUILD] $ /bin/sh -xe /tmp/jenkins3779972667920467885.sh
+ mvn package
[INFO] Scanning
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building pass_doc 0.0.1-RELEASE
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ scic_paas_doc ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 1 resource
[INFO] Copying 71 resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ scic_paas_doc ---
[INFO] Nothing to compile - all class are up to date
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ scic_paas_doc ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory /var/lib/jenkins/workspace/SCIC_DOC_TRIGGER_BUILD/src/test/resources [INFO]
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ scic_paas_doc ---
[INFO] No sources to compile
[INFO]
[INFO] --- maven-surefire-plugin:2.18.1:test (default-test) @ scic_paas_doc ---
[INFO] No tests to run.
[INFO]
[INFO] --- maven-jar-plugin:2.6:jar (default-jar) @ scic_paas_doc ---
[INFO] Building jar: /var/lib/jenkins/workspace/SCIC_DOC_TRIGGER_BUILD/target/scic_paas_doc-0.0.1-RELEASE.jar [INFO]
[INFO] --- spring-boot-maven-plugin:1.4.1.RELEASE:repackage (default) @ scic_paas_doc ---
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 3.695s
[INFO] Finished at: Fri Jul 28 09:15:43 CST 2017
[INFO] Final Memory: 16M/237M
[INFO] ------------------------------------------------------------------------
SSH: Connecting from host [jenkins]
SSH: Connecting with configuration [PAAS_DOC_SERVER_200] ...
SSH: EXEC: STDOUT/STDERR from command [/root/run.sh] ...mas是哪个国家的缩写
Checking scic document
killing old rvice - 19970 ...
Restarting
Restarted successfully.
buySSH: EXEC: completed after 200 ms
SSH: Disconnecting configuration [PAAS_DOC_SERVER_200] ...
SSH: Transferred 1 file(s)
Finished: SUCCESS
查看⽹站更新
发现确实已经更新啦。
参考⽂档

本文发布于:2023-07-12 19:21:34,感谢您对本站的认可!

本文链接:https://www.wtabcd.cn/fanwen/fan/78/1093029.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:配置   动化   安装   实现   容器   部署   高考
相关文章
留言与评论(共有 0 条评论)
   
验证码:
推荐文章
排行榜
Copyright ©2019-2022 Comsenz Inc.Powered by © 专利检索| 网站地图