限制Jenkins管道仅在特定节点上运行

时间:2017-03-07 15:46:50

标签: jenkins jenkins-pipeline

我正在建设将广泛使用Jenkins piplines的工作。我们的节点按照标签按项目指定,但与常规作业不同,管道构建似乎没有"限制此项目可以运行的位置"复选框。如何指定管道将以与常规作业相同的方式运行在哪个节点上?

3 个答案:

答案 0 :(得分:31)

执行node步骤时指定所需的节点或标记:

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

有关node的参数的扩展说明,请参阅https://jenkins.io/doc/pipeline/steps/workflow-durable-task-step/#code-node-code-allocate-node

答案 1 :(得分:23)

对于记录,我们也在这里有declarative pipeline示例(选择一个标签为' X'的节点):

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

答案 2 :(得分:5)

要清楚,因为管道有两个语法,所以有两种方法可以实现。

声明性

pipeline {
    agent none

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

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

脚本化

node('your-node') {
  try {

    stage 'Build'
    node('build-run-on-this-node') {
        sh ""
    }
  } catch(Exception e) {
    throw e
  }
}
相关问题