詹金斯(Jenkins)-在同一台机器上触发另一个管道作业-无需创建新的“执行程序" [英] Jenkins - Trigger another pipeline job in same machine - without creating new "Executor"

查看:325
本文介绍了詹金斯(Jenkins)-在同一台机器上触发另一个管道作业-无需创建新的“执行程序"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想做类似的事情-从触发器管道中调用" some_job_pipeline ",它将成为按参数执行的控制器,以在相同或某些特定的Jenkins节点上执行. 如果应在同一/主/父作业詹金斯节点上执行它-则不应创建新的执行程序".如果我将"Node1"设置为1,则节点执行程序将计数为1-作业将成功运行(不需要第二个执行程序).

I want to do similar thing - call "some_job_pipeline" from trigger pipeline and that it would be controller by parameter to execute on same or some specific Jenkins node. If it is should be executed on same/master/parent job jenkins node - it should not create new "Executor". That if i set for "Node1" node executors count to 1 - job would run successfully (would not require 2-nd executor).

例如,我有 Trigger_Main_Job ,它看起来像这样:

In example I have Trigger_Main_Job which looks something like this:

node("${params.JenkinsNode}") {
    stage("Stage 1") {
        ...
    }
    stage("some_job_pipeline") {
        build job: 'some_job_pipeline', parameters: []
    }
    stage("Stage 3") {
        ...
    }
    ...
}

some_job_pipeline ,看起来像这样: boolean runOnItsOwnNode = params.JenkinsNode?.trim()

and some_job_pipeline which looks something like this: boolean runOnItsOwnNode = params.JenkinsNode?.trim()

properties([
    parameters([
        string(name: 'JenkinsNode', defaultValue: '', description: 'Node from which to deploy. If "JenkinsNode" is not passed - then it will use parent job node.')
    ])
])

if(runOnItsOwnNode) {
    node("${params.JenkinsNode}") {
       print "Deploying from node: '${params.JenkinsNode}'"
    }
}
else {
    print "Deploying from parent job node."
    ???? THIS_IS MISSING_PART ????
}

注意:类似的问题,但指出应更改父管道:

Note: Similar question, but it point out that parent pipeline should be changed: Jenkins pipeline: how to trigger another job and wait for it without using an extra agent/executor. Question is is it possible to implement this and how without changing "Trigger" job. That I could create "some_job_pipeline" which execution would depend only on JenkinsNode passed parameter and not Parent/Called job implementation.

我尝试使用不同的变体来指定"???? THIS_IS MISSING_PART ????"代码部分 node("master"){...} 并且没有音符"和类似的东西.但是没有运气-"some_job_pipeline"仍然消耗/需要新的执行者.

I tried to different variants to specify "???? THIS_IS MISSING_PART ????" code part in node("master") {...} and without "note" and similar things. But no luck - "some_job_pipeline" still consumes/requires new executor.

推荐答案

查看"pipeline-build-step-plugin"参考:

Looking at "pipeline-build-step-plugin" ref :

https://jenkins .io/doc/pipeline/steps/pipeline-build-step/#-build-build-a-job

好像有一个参数:

$class: 'NodeParameterValue'

name
    Type: String
labels
    Array/List
    Type: String
nodeEligibility
    Nested Choice of Objects
    $class: 'AllNodeEligibility'
    $class: 'IgnoreOfflineNodeEligibility'
    $class: 'IgnoreTempOfflineNodeEligibility'

您可以用来将节点值传递给另一个作业.抱歉,我无法进行测试,我们只有一个节点在运行...

you can use to pass node values to another job. Sry, I can't do some testing, we only have one node running...

有关以下内容的更多详细信息:

More details on : https://github.com/jenkinsci/pipeline-build-step-plugin/blob/master/src/main/java/org/jenkinsci/plugins/workflow/support/steps/build/BuildUpstreamNodeAction.java

这篇关于詹金斯(Jenkins)-在同一台机器上触发另一个管道作业-无需创建新的“执行程序"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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