In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/03 Report--
Original articles, welcome to reprint. Reprint please indicate: reproduced from IT Story Association, thank you!
Original link address: "Advanced article" docker gitlab and jenkins-CICD process (43)
Gitlab and jenkins have been installed in the previous section, so this time we will string together the CICD process and experience CICD. The goal is to submit code in gitlab. Trigger a series of processes, and finally you can see the effect of the new code (machine content first, only mirrored packaging and push). Source code: https://github.com/limingios/msA-docker/vagrant master branch CICD
Understand git code submission to complete the construction of jenkins
The code was uploaded last time. Go to the project and select Integrations in settings.
Here you can configure a url, the default trigger trigger push
Where did the url address here come from? Please check jenkins, because there are many micro-services in gitlab, so select one of these services and create a new task name: user-edge-service, which allows url to trigger build tasks remotely.
The option to trigger a remote build (for example, using a script) is missing in the Job configuration in Jenkins
The features shown in the figure do not appear on the Job configuration page, which is due to permission issues:
Turn off to prevent cross-site request forgery
The URL address of gitlab's Integrations is modified:
Http://192.168.66.102:8888/job/user-edge-service/build?token=123456
Gitlab sets Webhooks to report an error Urlis blocked: Requests to localhost are not allowed. Admin login settings
The Integrations of gitlab has been added.
Jenkins has been added.
Take a test.
Return 201, indicating that the build returned success.
Construction description
All of our builds are based on pipline, and the script is done with groovy. If you can't check it, you can use pipeline syntax.
Start writing pipline
Jenkins Pipeline is a set of plug-ins that support the implementation and integration of continuous delivery Pipeline into Jenkins. Pipeline provides a set of extensible tools for creating simple to complex transport Pipeline for code through Pipeline DSL.
Try to write a test.
#! groovypipeline {/ / said earlier that jenkins supports clustering, but we don't need clustering here because of k8s. Any executes the agent any// environment variable on any available agent, and how is the environment {REPOSITORY= "ssh://git@192.168.66.101:2222/liming/microservice.git"} / / pipeline ahead of time All through the stagestages {stage ('get code') {steps {echo "start fetch code from git ssh://git@192.168.66.101:2222/liming/microservice.git" deleteDir () git "${REPOSITORY}"}} under many stages
}
! [] (https://upload-images.jianshu.io/upload_images/11223715-e24ac65f362158a1.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)> Click to build now Then check the results! [] (https://upload-images.jianshu.io/upload_images/11223715-1d6875f4d8f02ad8.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)![](https://upload-images.jianshu.io/upload_images/11223715-83a2782e8b8babe4.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)![](https://upload-images.jianshu.io/upload_images/11223715-84ac5d18ea312fe9.png?imageMogr2/auto- Orient/strip%7CimageView2/2/w/1240) > the container in which jenkins resides is not configured Send the secret key to the gitlab and configure it together! [] (```bashdocker psdocker exec-it d918e00a583f / bin/bashssh-keygen-t rsa-C "394498036@qq.com" cat / root/.ssh/id_rsa.pub on the host where https://upload-images.jianshu.io/upload_images/11223715-1c30c87effc06441.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)> enters 102s
Try to git clone in the container.
Try it. Build it now.
View the catalog
The maven repository address needs to be configured. Currently, this image nds is not recognized domestically and needs to be operated in the container.
Echo "nameserver 8.8.8.8" | tee / etc/resolv.conf > / dev/nullapt-get updateapt-get install vimcd / opt/maven/confvi settings.xmlmkdir / usr/lib/jvm/java-8-openjdk-amd64/lib
This problem can be solved by changing the maven image. Add a maven that changes the image address to Aliyun in the conf/settings.xml file of / opt/maven/conf under the maven installation directory, and it can be solved in mvn compile.
Nexus-aliyun*Nexus aliyun http://maven.aliyun.com/nexus/content/groups/public
If this error occurs, I can't find tool.jar to copy a tool.jar directly. I copied it in the source package.
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.3.2:compile (default-compile) on project message-thrift-service-api: Compilation failure [ERROR] Unable to locate the Javac Compiler in: [ERROR] / usr/lib/jvm/java-8-openjdk-amd64/jre/../lib/tools.jar [ERROR] Please ensure you are using JDK 1.4 or above and [ERROR] not a JRE (the com.sun.tools.javac.Main class is required ). In most cases you can change the location of your Java [ERROR] installation by setting the JAVA_HOME environment variable.
Copy command
Yum install lrzsz#rz Select tool.jardocker cp tool.jar container ID:/usr/lib/jvm/java-8-openjdk-amd64/jre/../lib/ tools.jar! [] (https://upload-images.jianshu.io/upload_images/11223715-27d864caa1b8bffa.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)> configuration environment variable ```bashdocker exec-it container ID / bin/bashvi ~ / .bashrc # configure the following environment Variable set JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64export PATH=$ {JAVA_HOME} / bin:$PATH
Try to build here
#! groovypipeline {/ / said earlier that jenkins supports clustering, but we don't need clustering here because of k8s. Any executes the agent any// environment variable on any available agent, environment {REPOSITORY= "ssh://git@192.168.66.101:2222/liming/microservice.git" MODULE= "user-edge-service"} / / how the pipeline is advanced All through stagestages {stage ('get code') {steps {echo "start fetch code from git ssh://192.168.66.101:2222/liming/microservice.git" deleteDir () git "${REPOSITORY}"} stage ('compilation + unit test') {steps {under many stages Echo "start compile" sh "mvn-U-pl ${MODULE}-am clean package"}
Jenkins completes the push to the official website image creation build-imge file docker login logs in to the docker repository (as mentioned before, my machine memory is too small to start the private docker repository, no matter which one is logged in on the jenkins machine, push will not make a mistake) cd ~ vi build-image.shchmod 775 build-image.shdocker login
#! groovypipeline {/ / said earlier that jenkins supports clustering, but we don't need clustering here because of k8s. Any executes agent any / / environment variables on any available agent, environment {REPOSITORY= "ssh://git@192.168.66.101:2222/liming/microservice.git" MODULE= "user-edge-service" SCRIPT_PATH= "/ root/"} / / how the pipeline is advanced All through stage stages {stage ('get code') {steps {echo "start fetch code from git ssh://192.168.66.101:2222/liming/microservice.git" deleteDir () git "${REPOSITORY}"} stage ('code static') under many stages State check') {steps {echo "start code check"} stage ('compilation + unit test') {steps {echo "start compile" sh "mvn-U-pl ${MODULE}-am clean package"}} Stage ('build image') {steps {echo "start build image" sh "# {SCRIPT_PATH} / build-image.sh ${MODULE}"} stage ('publish system') {steps {echo "start deploy" sh "# {SCRIPT_PATH} / deploy.sh ${MODULE} ${MODULE} "}
Build-image.sh
#! / bin/bashMODULE=$1TIME= `date "+% Y%m%d%H%M" `GIT_REVISION= `git log-1-- pretty=format: "% h" `IMAGE_NAME=zhugeaming/$ {MODULE}: ${TIME} _ ${GIT_REVISION} cd ${MODULE} docker build-t ${GIT_REVISION} .docker push ${GIT_REVISION}
Deply.sh
#! / bin/bashIMAGE= `cat IMAGE_ name `Deplouement = $1MODULE=$2echo "update image to ${IMAGE}" kubectl set image deployment/$ {DEPLOYMENT} ${MODULE} = ${MODULE}
PS: in conclusion, jenkins is not recommended to use container installation. I have installed at least a dozen pits with containers, which is good for understanding commands. Let me sum up a few points.
Don't containerize jenkins, just install it on the machine. The container itself is an individual, and if you think about it, you have to hold jdk,mvn,docker in it. If the jenkins is containerized, it means that the container still has to be filled with docker. Writing scripts using pipline is actually very simple. It is pipelined in itself, and it is more responsible for commands to recommend using shell scripts, which is also convenient for maintenance. In gitlab, outbound requests allows several important points in jenkins to be accessed across domains, and the process of allowing users to register and write is a bit complicated. I wrote it while practicing, but I recorded all kinds of problems I encountered, hoping to be helpful to the old guys with problems. The sh script inside may be more suitable for me, especially the build-image part, it is recommended to modify it. Don't install jenkins in a container. This hole is too big. Gitlab is still cool to install in a container. Finally, I would like to say that the pipline syntax of jenkins is not complicated. With reference to my writing, you can complete the automatic build, push image and update service. I am going to continue to study K8s. I feel that K8s is too deep. Next time I release the album, take a deep bite!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.