将 Jenkins 管道限制为仅在特定节点上运行 [英] Limiting Jenkins pipeline to running only on specific nodes

查看:34
本文介绍了将 Jenkins 管道限制为仅在特定节点上运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm building jobs that will be using Jenkins piplines extensively. Our nodes are designated per project by their tags, but unlike regular jobs the pipeline build does not seem to have the "Restrict where this project can be run" checkbox. How can I specify on which node the pipeline will run the way I do for regular jobs?

推荐答案

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

You specify the desired node or tag when you do the node step:

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 参数的扩展说明.

See https://jenkins.io/doc/pipeline/steps/workflow-durable-task-step/#node-allocate-node for an extended explanation of the arguments to node.

2019 年这个答案(和问题)是在 2017 年提出的,当时只有一种 Jenkins 流水线,脚本化流水线,从那时起就添加了声明性流水线.所以上面的答案对于脚本管道是正确的,关于声明性管道的答案请参见下面的其他答案.

Edit 2019: This answer (and question) was made back in 2017, back then there only was one flavor of Jenkins pipeline, scripted pipeline, since then declarative pipeline has been added. So above answer is true for scripted pipeline, for answers regarding declarative pipeline please see other answers below.

这篇关于将 Jenkins 管道限制为仅在特定节点上运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆