如何使用管道插件在特定节点上触发 jenkins 构建? [英] How to trigger a jenkins build on specific node using pipeline plugin?

查看:33
本文介绍了如何使用管道插件在特定节点上触发 jenkins 构建?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个名为TestPipeline"的 Jenkins 管道作业.我想在标记为tester1"和tester2"的 2 个不同从站上触发构建.这里的管道脚本非常简单:

I have a Jenkins pipeline job called "TestPipeline". I want to trigger a build on 2 different slaves which labeled "tester1' and "tester2". And the pipeline script is quite simple here:

node('tester1') {
    build 'test_job'
}
node('tester2') {
    build 'test_job'
}

但是,当我运行 TestPipeline 作业时,test_job"不会在我分配的节点上运行.但改为在随机节点上运行.

However when I run the TestPipeline job, the "test_job" won't run on the nodes which I assigned. But run on random node instead.

我想知道是否应该在我的test_job"上设置限制该项目可以运行的位置".所以我将它设置为tester"(tester"标签包含节点tester1"和tester2").但是当我再次运行管道作业时,test_job"在tester2"上运行了两次.我应该期望作业首先在tester1"上运行,然后在tester2"上运行.这是为什么?是不是因为构建步骤应该建立在哪个节点上时,节点"步骤并不重要?

I'm wondering if I should set "Restrict where this project can be run" on my "test_job". So I set it to "tester" (The "tester" label contains both node "tester1" and "tester2"). But when I run the pipeline job again, the "test_job" runs on "tester2" twice. I should expect the job to run on "tester1" first and then run on "tester2". Why is that? Is it because the "node" step doesn't matter when it comes to which node the build step should be built on?

推荐答案

请查看错误 这里.解决方法如下.

Please see the bug here. The solution is as follows.

  1. 安装节点和标签参数插件
  2. 在test_job的配置中,选择'This build is parameterized'并添加一个Label参数并将参数名称设置为'node'
  3. 在管道脚本中,使用代码:

build job: 'test_job', parameters: [[$class: 'LabelParameterValue', name: 'node', label: 'tester1']]
build job: 'test_job', parameters: [[$class: 'LabelParameterValue', name: 'node', label: 'tester2']]

工作将按照我的意愿构建.

And the job will be built as I wanted.

不过,我认为这只是一种解决方法.我仍然相信这是一个错误.因为节点步骤应该做它的工作,而不是让其他插件来做它.

However, I think it is only a workaround. I still believe this is a bug. Because the node step should do its job instead of letting other plugins to do for it.

这篇关于如何使用管道插件在特定节点上触发 jenkins 构建?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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