0

I'm kind of new to Jenkins, I'd like to setup Jenkins trigger for the following case, successful build of either projA or projB should trigger build of projC, I'm using declarative Jenkins syntax, and projA..C are multi-branch projects.

projA --> projC projB --> projC

I follow the example of #2 from Jenkins: Trigger Multi-branch pipeline on upstream change and setup projC to be triggered on projA (or projB), but not sure the syntax for projC to be triggered either on projA or projB.

In addition, is it possible to pass values from projA and projB to projC as part of the triggering mechanism? What's the syntax if possible.

Any help is appreciated.

This is the code:

pipeline { 
    agent any 

    parameters { 
        string(name: 'MY_BRANCH_NAME', defaultValue: '${env.BRANCH_NAME}', description: 'pass branch value') 
        string(name: 'MY_VERSION', defaultValue: '1.23', description: 'My version') 
    }

    stages {
        stage('Build in dev') { 
            steps { 
                echo 'Building dev..' 
            } 
        } 
    }
}
waka
  • 3,362
  • 9
  • 35
  • 54
tonywl
  • 131
  • 2
  • 10
  • Show us the pipeline code you use. – Jeroen Heier Oct 16 '17 at 03:56
  • My pipeline is pretty generic, here is the skeleton pipeline { agent any parameters { string(name: 'MY_BRANCH_NAME', defaultValue: '${env.BRANCH_NAME}', description: 'pass branch value') string(name: 'MY_VERSION', defaultValue: '1.23', description: 'My version') } stages { stage('Build in dev') { steps { echo 'Building dev..' } } } } sorry about the formatting. – tonywl Oct 16 '17 at 04:02

1 Answers1

0

I think you need to look at this from the other way around. Don't think of C looking for A or B to complete. Think of A or B triggering C if they succeed.

In your A and B projects, if you consider the build to be successful by whatever your criteria is, use the build step to trigger C.

If you want to pass simple values to C, make C a parameterized build and pass the parameters in the build step.

post{
    success{
        build job: 'C', parameters: [booleanParam(name: 'bool1', value: true), string(name: 'foo', value: 'bar')], quietPeriod: 10
    }
}
Rob Hales
  • 5,123
  • 1
  • 21
  • 33
  • I was looking for syntax example for triggering based on multiple upstream projects, but I think this would work. I don't find document on declarative syntax for either 'build' or 'triggers'. any pointer? Thanks. – tonywl Oct 16 '17 at 04:22
  • Find build steps here. https://jenkins.io/doc/pipeline/steps/. Look for the "Pipeline build Step plugin". Triggers are here: https://jenkins.io/doc/book/pipeline/syntax/#triggers – Rob Hales Oct 16 '17 at 04:31
  • I'm getting "Waiting for non-job items is not supported" from Jenkins when specifying one of my project name as value for 'job', e.g. build job: 'test3', parameters: ..., Does it mean Jenkins couldn't find test3 as project? – tonywl Oct 27 '17 at 17:00