![](/img/trans.png)
[英]Jenkins Date Parameter Plugin - How to use it in a Declarative Pipeline
[英]How to use NodeLabel parameter plugin in declarative pipeline
我试图将我的自由式工作转换为声明性管道工作,因为管道提供了更大的灵活性。 但是,我无法弄清楚如何在管道中使用 NodeLabel 参数插件( https:\/\/wiki.jenkins.io\/display\/JENKINS\/NodeLabel+Parameter+Plugin<\/a> )。
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')
}
}
}
}
这是一个完整的例子:
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'
}
}
}
}
}
}
假设您使用管道上的 NodeLabel 插件添加了参数(比如名为slaveName
)。 您现在需要提取slaveName
的值并将其输入到slaveName
>node->label 字段中。
您可以使用代理内部的节点属性指定节点。 像这样 -
agent
{
node
{
label "${slaveName}"
}
}
以下脚本对我有用,可以在不同的节点上并行运行多个作业。
我从构建步骤插件文档中获取了参考。
https:\/\/www.jenkins.io\/doc\/pipeline\/steps\/pipeline-build-step\/<\/a>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.