我正在尝试将我的自由式作业转换为声明性管道作业,因为管道提供了更大的灵活性。我不知道如何使用 NodeLabel 参数插件(https://wiki.jenkins.io/display/JENKINS/NodeLabel+Parameter+Plugin https://wiki.jenkins.io/display/JENKINS/NodeLabel+Parameter+Plugin)但是在管道中。
pipeline {
agent any
parameters {
// Would like something like LabelParameter here
}
stages {
stage('Dummy1') {
steps {
cleanWs()
sh('ls')
sh('pwd')
sh('hostname')
}
}
stage('Dummy2') {
steps {
node("comms-test02") {
sh('ls')
sh('pwd')
sh('hostname')
}
}
}
}
我基本上只需要一种使用指定构建作业位置的参数(使用从属标签)来启动作业的方法。
詹金斯需要一个代理字段,我将其设置为“任何”。但好像没有可用的标签参数?
作为替代方案,我尝试使用“节点”命令(https://jenkins.io/doc/pipeline/steps/workflow-durable-task-step/#-node- https://jenkins.io/doc/pipeline/steps/workflow-durable-task-step/#-node-分配节点)。但这给我留下了两份正在运行的工作,在工作时,它们看起来并不那么漂亮。
有谁可以使用 NodeLabel 参数插件吗?或者也许有人有更干净的方法?
编辑:也许我不清楚。我需要能够在不同的节点上运行作业。在触发作业时应通过参数决定要运行的节点。节点标签插件完美地做到了这一点。但是,我无法在管道中重现这种行为。
这是一个完整的示例:
pipeline {
parameters {
choice(name: 'node', choices: [nodesByLabel('label')], description: 'The node to run on') //example 1: just listing all the nodes with label
choice(name: 'node2', choices: ['label'] + nodesByLabel('label'), description: 'The node to run on') //example 2: add the label itself as the first choice to make "Any of the nodes" the default choice
}
agent none
stages {
stage('Test') {
agent { label params.node}
stages {
stage('Print environment settings') {
steps {
echo "running on ${env.NODE_NAME}"
sh 'printenv | sort'
}
}
}
}
}
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)