Limiting Jenkins pipeline to running only on specific nodes

你离开我真会死。 提交于 2019-12-03 00:58:56

You specify the desired node or tag when you do the node step:

node('specialSlave') {
   // Will run on the slave with name or tag specialSlave
}

See https://jenkins.io/doc/pipeline/steps/workflow-durable-task-step/#code-node-code-allocate-node for an extended explanation of the arguments to node.

For the record let's have the declarative pipeline example here as well (choosing a node which has the label 'X'):

pipeline {
    agent { label 'X' }
...
...
}

To be clear, because Pipeline has two Syntax, there are two ways to achieve that.

Declarative

pipeline {
    agent none

    stages {
        stage('Build') {
            agent { label 'slave-node​' }
            steps {
                echo 'Building..'
                sh '''
                '''
            }
        }
    }

    post {
        success {
            echo 'This will run only if successful'
        }
    }
}

Scripted

node('your-node') {
  try {

    stage 'Build'
    node('build-run-on-this-node') {
        sh ""
    }
  } catch(Exception e) {
    throw e
  }
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!