In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)05/31 Report--
This article is about how to create a pipeline task under a Jenkins cluster. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.
Environmental information
There are three computers in the whole cluster environment. The information is as follows: | Host name | IP address | function | |-| master | 192.168.133.131 | master node of Jenkins cluster, which provides web service | | agent1 | 192.168.133.132 | No.1 worker node of Jenkins cluster, labeled maven | | agent2 | 192.168.133.133 | No.2 worker node of Jenkins cluster, labeled with gradle |
Actual combat content
This actual combat is to experience Jenkins cluster performing two tasks at the same time, both of which are popular open source projects on compiling and building GitHub:
Compile and build spring-cloud-alibaba on agent1, and then transfer the build results to the / usr/local/build_result directory of the master computer through the scp command
Compile and build spring-framework in agent2, and then transfer the build result to the / usr/local/build_result directory of the master computer through the scp command
Preparatory work
The following preparatory work must be done to successfully carry out the follow-up tasks:
Create a folder / usr/local/build_result on your master computer
Configure maven and select Global Tool Configuration on the Jenkins web page, as shown in the red box below:
Add a new maven configuration named mvn-3.6.2, and then click the "Save" button, as shown below:
When you use the scp command on agent1 and agent2 to transfer files to master, you need to enter "yes" in the console for the first time. In order to avoid waiting for input when performing a task, we will manually execute it again, and then we will never use it again. After ssh logs in to agent1, execute the following command to enter the container:
Docker exec-it agent / bin/bash
When you execute the command ssh root@192.168.133.131, the console prompts you to enter yes or no. Please enter yes, and then enter the password of master according to the prompt. Login to master is successful:
[root@agent1 16] # docker exec-it agent / bin/bashroot@82eb8cfec0a6:/# ssh root@192.168.133.131The authenticity of host '192.168.133.131 (192.168.133.131)' can't be established.ECDSA key fingerprint is SHA256:DPE2nldWHiOhC4DB9doy7jPWNZVup6XFZ+sR2i1gqz8.Are you sure you want to continue connecting (yes/no)? YesWarning: Permanently added '192.168.133.131' (ECDSA) to the list of known hosts.root@192.168.133.131's password: Last login: Sat Nov 16 19:59:42 2019 from 192.168.133.132
At this point, you log in to master with ssh in the container of agent1, so you have to enter the exit command twice in a row to return to the console of agent1.
Perform the same operation on an agent2 computer
At this point, you are ready to create a task
The task of compiling and building spring-cloud-alibaba
Spring-cloud-alibaba is a maven project that needs to be compiled and built with maven:
On the Jenkins page, click the red box below to create a task:
As shown in the following figure, create a pipeline task named spring-clolud-alibaba:
The red box in the following figure is where you enter the pipeline script:
Enter the following in the red box in the image above:
Pipeline {agent {label 'maven'} tools {maven' mvn-3.6.2'} stages {stage (' Checkout') {steps {echo 'download the source code (2.1.1.RELEASE archive package)' sh 'wget https://github.com/alibaba/ of the spring-cloud-alibaba project from GitHub Spring-cloud-alibaba/archive/v2.1.1.RELEASE.tar.gz' echo 'download is over Extract the archive package'sh 'tar-zxf v2.1.RELEASE.tar.gz'} stage (' Build') {steps {echo'to build'sh'cd spring-cloud-alibaba-2.1.1.RELEASE & & mvn clean package-U-DskipTests' }} stage ('Save') {steps {echo' transfers the build result to the storage server'sh'cd spring-cloud-alibaba-2.1.1.RELEASE/spring-cloud-alibaba-nacos-discovery/target & & sshpass-p 888888 scp. / * .jar root@192.168.133.131:/usr/local/build_result 'echo' transmission completed'} stage ('Clean') {steps {echo' clean up Maven project'sh'cd spring-cloud-alibaba-2.1.1.RELEASE & & mvn clean' echo 'clean up'}
After clicking the "Save" button at the bottom, click "build now" in the red box below to start the task:
Click the red ball in the red box below to jump to the page where task information is output in real time:
The page outputs the construction information in real time:
On the main page, you can see that agent1 is performing the task. As shown in the red box below, you can see that the tag in the pipeline script has taken effect. Schedule the task to the node labeled maven to execute: compiling and building the spring-cloud-alibaba project is a time-consuming operation. Let's now create another task: compile and build spring-framework.
The task of compiling and building spring-framework
Spring-framework is a gradle project. There is no need to prepare the gradle environment. The gradle tool is automatically downloaded when the compilation command is executed:
Create a pipeline task named spring-framework:
The pipeline script is as follows:
Pipeline {agent {label 'gradle'} stages {stage (' Checkout') {steps {echo 'download the source code (master branch)' checkout of the spring-framework project from GitHub ([$class: 'GitSCM', branches: [[name:' * / master']], doGenerateSubmoduleConfigurations: false, extensions: [], submoduleCfg: [] UserRemoteConfigs: [[url: 'https://github.com/spring-projects/spring-framework.git']]])}} stage (' Build') {steps {echo 'starts compiling and building' sh'. / gradlew build'}} stage ('transfer ) {steps {echo 'transfers the build result to the storage server' sh'cd spring-core/build/libs & & sshpass-p 888888 scp. / * .jar root@192.168.133.131:/usr/local/build_result & & cd.. /.. /..' Echo 'transfer complete'} stage ('Clean') {steps {echo' clean up gradle project'sh'. / gradlew clean' echo 'clean up'}
Execute this task immediately. It can be seen that the task has been scheduled to agent2 for execution. At this time, agent1 and agent2 are executing the task at the same time, as shown in the following figure:
View build results
After the above two tasks are successfully built, the scp command will be used to transfer the build results to the / usr/local/build_result directory of master:
[root@master build_result] # lsagent.jar spring-cloud-alibaba-nacos-discovery-2.1.1.RELEASE.jar spring-cloud-alibaba-nacos-discovery-2.1.1.RELEASE-sources.jar spring-objenesis-repack-3.1.jarspring-cglib-repack-3.3.0.jar spring-cloud-alibaba-nacos-discovery-2.1.1.RELEASE-javadoc.jar spring-core-5.2.2.BUILD-SNAPSHOT.jar
At this point, the actual combat of pipeline under the Jenkins cluster is completed. With the help of the tag parameters of pipeline, the scheduling node of the task can be controlled, and multi-tasks can be executed on multiple nodes at the same time.
Thank you for reading! This is the end of the article on "how to create pipeline tasks under the Jenkins cluster". I hope the above content can be helpful to you, so that you can learn more knowledge. if you think the article is good, you can share it for more people to see!
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.