pipeline under real cluster Jenkins

About Jenkins cluster

In "Jenkins quickly build cluster" in one article, we use docker Jenkins quickly build a cluster, create a pipeline task today in this cluster environment, experience parallel tasks under Jenkins cluster;

Environmental Information

The entire cluster environment, a total of three computers, information is as follows:
| hostname | IP address | action |
| - | - | - |
| master | 192.168.133.131 | Jenkins cluster master node to provide web services |
| AGENT1 | 192.168.133.132 | One Jenkins work to the node cluster, the label is Maven |
| Agent 2 | 192.168.133.133 | Jenkins II work to the node cluster, the label is Gradle |

Actual content

The actual combat experience to perform two tasks simultaneously Jenkins clusters are compiled builds popular open source projects on GitHub:

  1. Compile and build spring-cloud-alibaba on agent1, then constructed by scp command transfer result to the master computer / usr / local / build_result directory;
  2. Agent2 compile and build the spring-framework, and then transmits the result to the master computer constructed by scp command / usr / local / build_result directory;

Ready to work

The following preparatory work to be done in order to successfully execute subsequent tasks:

  1. Created on the master computer folder / usr / local / build_result
  2. Configuration maven, selected on the page Jenkins Free Join the Configuration Tool , as shown in FIG red box:
    Here Insert Picture Description
  3. Add a maven configuration called mvn-3.6.2 , then click the "Save" button, as shown below:
    Here Insert Picture Description
  4. agent1 and when to use scp command to transfer files to the master on agent2, for the first time in the console ssh to enter "yes", in order to avoid the emergence of this mission when waiting for input operation, we have to manually perform again, back on again do not, and after ssh login agent1, execute the following command into the container:
docker exec -it agent /bin/bash
  1. Run SSH [email protected] , this time the console prompt enter yes or NO , please enter yes , then follow the prompts to enter the master password, then log in successfully master:
[root@agent1 16]# docker exec -it agent /bin/bash
root@82eb8cfec0a6:/# ssh [email protected]
The 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)? yes
Warning: Permanently added '192.168.133.131' (ECDSA) to the list of known hosts.
[email protected]'s password: 
Last login: Sat Nov 16 19:59:42 2019 from 192.168.133.132
  1. At this point you are in agent1 ssh to log container in the master, so you want to enter two exit command to return to agent1 console;
  2. Also perform the same operation on a computer agent2;

At this point, ready, you can create a task;

Compiled builds spring-cloud-alibaba task

spring-cloud-alibaba is a maven project, use maven to compile build:

  1. Jenkins on the page, click on the red box at the location, create a task:
    Here Insert Picture Description
  2. The following diagram, created called the Spring-clolud-alibaba Pipeline tasks:
    Here Insert Picture Description
  3. Half moon position is to enter the pipeline script places:
    Here Insert Picture Description
  4. Enter the following positions in the red box:
pipeline {
    agent {
        label 'maven'
    }
    tools {
        maven 'mvn-3.6.2'
    }
    stages {
        stage('Checkout') {
            steps {
                echo '从GitHub下载spring-cloud-alibaba工程的源码(2.1.1.RELEASE归档包)'
                sh 'wget https://github.com/alibaba/spring-cloud-alibaba/archive/v2.1.1.RELEASE.tar.gz'
                echo '下载结束,解压归档包'
                sh 'tar -zxf v2.1.1.RELEASE.tar.gz'
            }
        }        
        stage('Build') {
            steps {
                echo '开始编译构建'
                sh 'cd spring-cloud-alibaba-2.1.1.RELEASE && mvn clean package -U -DskipTests'
            }
        }
        stage('Save') {
            steps {
                echo '将构建结果传送到存储服务器'
                sh 'cd spring-cloud-alibaba-2.1.1.RELEASE/spring-cloud-alibaba-nacos-discovery/target && sshpass -p 888888 scp ./*.jar [email protected]:/usr/local/build_result'
                echo '传送完毕'
            }
        }
        stage('Clean') {
            steps {
                echo '清理Maven工程'
                sh 'cd spring-cloud-alibaba-2.1.1.RELEASE && mvn clean'
                echo '清理完毕'
            }
        }
    }
}
  1. Click the bottom of the "Save" button, click below the red box "immediately build" to start tasks:

Here Insert Picture Description

  1. Click below the red box red ball, to jump to the page output in real-time task information:
    Here Insert Picture Description

  2. Real-time output page build information:
    Here Insert Picture Description

  3. Main page you can see a agent1 on a mission, the red box shown in the following figure, visible pipeline script tag already in force, and the task is scheduled to label maven node to perform:
    Here Insert Picture Description
    compiled builds spring-cloud-alibaba project is a time-consuming operation, we are now going to create another task: to compile build spring-framework

    Compiled builds spring-framework of the task

    spring-framework is gradle engineering, need to prepare gradle environment, in the implementation of the compiler command will automatically download gradle tools:
  4. Creating named the Spring-Framework Pipeline tasks:
  5. pipeline script as follows:
pipeline {
    agent {
        label 'gradle'
    }

    stages {
        stage('Checkout') {
            steps {
                echo '从GitHub下载spring-framework工程的源码(master分支)'
                checkout([$class: 'GitSCM', branches: [[name: '*/master']], doGenerateSubmoduleConfigurations: false, extensions: [], submoduleCfg: [], userRemoteConfigs: [[url: 'https://github.com/spring-projects/spring-framework.git']]])
            }
        }        
        stage('Build') {
            steps {
                echo '开始编译构建'
                sh './gradlew build'
            }
        }
        stage('传送构建结果') {
            steps {
                echo '将构建结果传送到存储服务器'
                sh 'cd spring-core/build/libs && sshpass -p 888888 scp ./*.jar [email protected]:/usr/local/build_result && cd ../../..'
                echo '传送完毕'
            }
        }
        stage('Clean') {
            steps {
                echo '清理gradle工程'
                sh './gradlew clean'
                echo '清理完毕'
            }
        }
    }
}
  1. Immediately perform this task, the task has been scheduled to be seen agent2 up is performed, and at this time agent1 agent2 tasks are executed simultaneously, as shown below:
    Here Insert Picture Description

    View build results

    Both tasks after successfully constructed, will be constructed by the master results to scp command / usr / local / build_result directory:
[root@master build_result]# ls
agent.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.jar
spring-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 pipeline under Jenkins cluster is complete, with the label parameters can be controlled pipeline scheduling nodes tasks, multi-task at the same time in a multi-node execution;

Welcome to public concern number: Programmer Chen Xin

Guess you like

Origin www.cnblogs.com/bolingcavalry/p/11874732.html