Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jenkins launch job through DSL and do not wait for job to finish

Im trying to launch a project through Jenkins DSL but dont need to wait for it to complete. Basically i want it to kick off an orphan job.

node("slave-node")
{
    // Launch pipeline job
    stage("LaunchPipelineJob")
    {
        // this step runs for x mins and does a buch of work
        echo "Starting pipelinejob"
        def pipelinejob  = build job: 'pipelineStep'
        //echo "Pipeline job status: ${pipelinejob.result}"
    }

    // Launch the orphan
    stage("LaunchOrphanJob")
    {
        // need to kick off this job, but dont care to wait for it to finish
        echo "Starting orphanPipelinejob"
        def orphanPipelinejob  = build job: 'orphanStep'
    }
}

i have looked over the dsl but cant find any docs on how to start an orphan. Thank you

like image 631
Lukas Gravley Avatar asked Aug 23 '17 20:08

Lukas Gravley


People also ask

What is DSL in Jenkins pipeline?

Job DSL was one of the first popular plugins for Jenkins which allows managing configuration as code and many other plugins dealing with this aspect have been created since then, most notably the Jenkins Pipeline and Configuration as Code plugins.

How do I invoke Jenkins job in pipeline?

Create a pipeline . In the Configuration stage of your new pipeline, add a trigger . Select Jenkins from the Type menu, which brings up the following screen: Select a Jenkins master from the Master drop-down menu, then select a job from the Job drop-down.

What is job-DSL in Jenkins?

For the rest of you, a quick refresher: job-dsl is a way of creating Jenkins jobs with code instead of the GUI. Here’s a very simple example: When processed via a Jenkins seed job, this code will turn into the familiar Jenkins jobs you know and love. What are Pipelines?

Why is job DSL not working in Jenkin?

Note: If searching for Job DSL returned no results, it either means the Job DSL plugin is already installed, or that your Jenkin server’s plugin list is not updated. You can check if the Job DSL plugin is already installed by navigating to your_jenkins_url /pluginManager/installed and searching for Job DSL.

How to add an additional pipeline job to Jenkins job DSL?

If any of them are not installed, go to your_jenkins_url /pluginManager/available and search for and select the plugins, then click Install without restart. Now that the required plugins are installed, let’s shift our focus to modifying your Job DSL script to include an additional pipeline job.

How do I create a seed job in Jenkins?

To create the seed job, go to your_jenkins_url, log in (if necessary), click the New Item link on the left of the dashboard. On the screen that follows, type in seed, select Freestyle project, and click OK. In the screen that follows, scroll down to the Build section and click on the Add build step dropdown. Next select Process Job DSLs.


2 Answers

This should do it.

build job: 'pipelineStep', propagate: false, wait: false

like image 94
Onur Gokkocabas Avatar answered Oct 12 '22 08:10

Onur Gokkocabas


stage{
    build job: 'pipelineStep', parameters: [string(name: 'xxx', value: xxx), string(name: 'yyy', value: yyy)],wait:false
} 
stage{
    build job: 'orphanStep', parameters: [string(name: 'xxx', value: xxx), string(name: 'yyy', value: yyy)],wait:false
}

FYI, when you give, wait = false, The runwrapper won't return any object, so you will not be able to fetch any details related to child jobs (pipelineStep and orphanStep).

RunWrapper.html

like image 31
Dhritiman Ghosh Avatar answered Oct 12 '22 08:10

Dhritiman Ghosh