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

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

问题描述

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

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的配置中,选择此构建已参数化"并添加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天全站免登陆