我想通过Node and Label插件运行将节点设置为参数的管道。
如何更改声明性管道
pipeline {
agent {
label 'whatever'
}
...
使用EXECUTION_NODE作为代理执行管道?这似乎比我想象的要复杂得多,或者我缺少明显的东西。
答案 0 :(得分:0)
问题是这样的:要向您展示“使用参数构建”页面,Jenkins需要运行您的管道并解析其参数。为了运行管道,Jenkins需要一个节点。要拥有一个节点,它将解析您的管道。因此,在显示对话框时,该节点已被选中。而且,在声明式管道中,所有阶段的所有节点都在开始时被选择。
您可以通过运行node
并提供params.EXECUTION_NODE
作为标签,尝试运行脚本化管道或脚本化和声明性的组合。脚本化管道逐行执行脚本。
编辑:这有效:
NODE = null
echo "This should be Null: $NODE"
node() {
stage("Define node") {
NODE = params.NODE
echo "This is now $NODE"
}
}
pipeline {
agent { node { label "$NODE" }}
parameters { string(name: 'NODE', defaultValue: 'some_node', description: '') }
stages {
stage("Main") {
steps {
echo "Hi"
}
}
}
}
以下是第二次运行的输出,其中以“ master”作为参数:
Started by user marat
Running in Durability level: MAX_SURVIVABILITY
[Pipeline] Start of Pipeline
[Pipeline] echo
This should be Null: null
[Pipeline] node
Running on Jenkins in /home/jenkins/workspace/test
[Pipeline] {
[Pipeline] stage
[Pipeline] { (Define node)
[Pipeline] echo
This is now master
[Pipeline] }
[Pipeline] // stage
[Pipeline] }
[Pipeline] // node
[Pipeline] node
Running on master in /var/jenkins_home/workspace/test
[Pipeline] {
[Pipeline] stage
[Pipeline] { (Main)
[Pipeline] echo
Hi
[Pipeline] }
[Pipeline] // stage
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
Finished: SUCCESS