1. 程式人生 > >【Jenkins】新版本的特性:自定義流水線

【Jenkins】新版本的特性:自定義流水線

#!/usr/bin/env groovy

pipeline {
    agent none
    stages {
        stage('stage-01') {
            agent { label 'master' }
            steps {
                echo 'stage-01'
                sh 'ifconfig ens33'
            }
        }        
        stage('stage-02') {
            agent { label '10.91.3.213
' } steps { echo 'stage-02' sh 'source /etc/profile && source ~/.bash_profile && ifconfig ens33' } } stage('stage-03') { agent { label '10.91.3.214' } steps { echo 'stage-03' sh
'source /etc/profile && source ~/.bash_profile && ifconfig ens33' } } stage('stage-04') { steps { script { // labels for Jenkins node types we will build on def labels = ['master', '10.91.3.213', '
10.91.3.214'] def builders = [:] for (x in labels) { def label = x // Need to bind the label variable before the closure - can't do 'for (label in labels)' // Create a map to pass in to the 'parallel' step so we can fire all the builds at once builders[label] = { node(label) { // build steps that should happen on all nodes go here echo 'stage-04 running on: ' + label // sh 'source /etc/profile && source ~/.bash_profile && echo "stage-04 running on all nodes"' } } } parallel builders } } } } }