我正在建立将广泛使用Jenkins基准线的工作。我们的节点是通过项目的标签来指定的,但是与常规作业不同,管道构建似乎没有“限制在何处可以运行此项目”复选框。如何指定管道将在常规作业上以哪种方式运行?
[在执行node
步骤时指定所需的节点或标签:
node('specialSlave') {
// Will run on the slave with name or tag specialSlave
}
请参见https://jenkins.io/doc/pipeline/steps/workflow-durable-task-step/#node-allocate-node,以获取对node
参数的扩展解释。
为了记录,我们这里也有declarative pipeline示例(选择一个带有标签'X'的节点):
pipeline {
agent { label 'X' }
...
...
}
要清楚,因为管道具有两个语法,所以有两种方法可以实现。
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
}
}