Jenkins - Trigger another pipeline job in same machine - without creating new “Executor”

淺唱寂寞╮ 提交于 2020-01-14 05:23:30

问题


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).

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") {
        ...
    }
    ...
}

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.

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.


回答1:


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

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

it looks like there's is a parameter :

$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



来源:https://stackoverflow.com/questions/59608367/jenkins-trigger-another-pipeline-job-in-same-machine-without-creating-new-e

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!