How to start a job from another job in a declarative pipeline?

88 views
Skip to first unread message

Idan Adar

unread,
Apr 12, 2017, 3:53:50 AM4/12/17
to Jenkins Users
Hi,

Lets assume there are two job:

1. a job for a micro-service repository
2. a job for end-to-end tests

I'd like, in specific cases, to start the end-to-end tests job from the micro-service job.
For example, after introducing a change that even though passed unit testing and integration testing, it needs further testing, available in the end-to-end tests job.

I'd like for the developers to make a commit with a specific phrase, e.g. "[e2e]" and to use it as follows (just pseudo code for now).

pipeline {
   
...
   
...
    stages
{
       
...
   
}    


    post
{
        success
{
           
if (BRANCH_NAME == "develop") {
                result
= sh (script: "git log -1 | grep '.*\\[e2e\\].*'", returnStatus: true)
               
if (result == 0) {
                   
// start the d2d job
               
}
           
}
       
}
   
...
   
...
   
}
}



Danny Rehelis

unread,
Apr 12, 2017, 4:40:41 AM4/12/17
to Jenkins Users
This is how I do this, should be easy enough -

pipeline {
stages {
        stage ('xxx') {
            steps {
...
...
                build job: '<job-name-here>', parameters: [
                    string(name: 'PARAM1', value: "xxx"),
                    string(name: 'PARAM2, value: "yyy")
                ]
            }
      }
}


--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-use...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/db4e7ca4-4a8b-4a70-ae49-6595eda541b7%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Idan Adar

unread,
Apr 12, 2017, 4:59:08 AM4/12/17
to Jenkins Users
Yep, found "build" as well. I thought maybe it's done differently in declarative pipelines...

Ended up with the following, however despite this, it did not start.

post {
   
// Run end-to-end tests, if requested
   success
{
      script
{

         
if (BRANCH_NAME == "develop") {
            result
= sh (script: "git log -1 | grep '.*\\[e2e\\].*'", returnStatus: true)
           
if (result == 0) {

               build job
: '****', wait: false
           
}
         
}
     
}
   
}
}

The following was logged: 

+ git log -1
+ grep '.*\[e2e\].*'
    Run tests [e2e]
[Pipeline] build (Building ****)
Scheduling item: ****

But when visiting that job's Stages View, there is no build running.
Could this be because the end-to-end job is also scheduled to run at specific time? Its Jenksinfile has the following specified: 

pipeline {
    triggers
{

        cron
('0 12,16,20 * * 1-4,7')
   
}
   
...


(run everyday except Friday and Saturday, at 12:00, 16:00 and 20:00).

Idan Adar

unread,
Apr 13, 2017, 3:42:46 AM4/13/17
to Jenkins Users
I should mention that both jobs are multi-branch jobs...
should the job name also somehow incorporate the branch name? i.e. "develop"

Idan Adar

unread,
Apr 13, 2017, 4:11:47 AM4/13/17
to Jenkins Users
That was it... just had to specify the branch. d'oh.

 build job: '****/master', wait: false
Reply all
Reply to author
Forward
0 new messages