user1107753
user1107753

Reputation: 1646

Jenkins trigger build dependent on build parameters

I have a jenkins pipeline set up as follows where Build A is the start of the pipeline and on completion triggers build B and so on (see below)..So far I have implemented Build A, B and C. I have used the Jenkins Parameterized Trigger plugin as a post build action to trigger my builds.

Is there anyway that I can after Build B has completed depending on what parameters the build was kicked off with fork the build after build B as shown below. Build C and Build D are deployment builds which will deploy to different environments. So if develop was passed as a parameter to Build A then it would invoke Build C else if test was passed as a param it would invoke Build D after Build B.

Been looking around and cant see how to do this anyone any ideas

Thanks

Parameterised Build A eg: Params a=1 b=2
              |
              |
Parameterise Build B (uses params from build A)
              |
              |
    ------------------------
    |                       |
    |                       |


Build C                   Build D

Upvotes: 1

Views: 2721

Answers (2)

Christopher Orr
Christopher Orr

Reputation: 111623

You can use the Pipeline Plugin (previously called workflow) to set this up pretty easily.

Create a new Pipeline job, check the "This build is parameterised" option, and create the two string parameters you want (e.g. server and foo), then define your pipeline script like this:

// Pass the parameters used to start this pipeline into the first two jobs
def p = [
  [$class: 'StringParameterValue', name: 'server', value: server],
  [$class: 'StringParameterValue', name: 'foo', value: foo]
]

// Build the first job and wait for success
build job: 'one', parameters: p

// Build the second job and wait for success
build job: 'two', parameters: p

// Decide which job to build next, and then start it
def deployJob = (server == 'develop') ? 'three' : 'four'
build deployJob

This will start your first two jobs with the same parameters (which I've also called server and foo in this example), and then clearly will start a build of only one other job, depending on what the value of the server parameter was when starting the pipeline.

Upvotes: 3

user1107753
user1107753

Reputation: 1646

I did this using the flexible publisher plugin and using a regualr expression on the parameter name to decide which build to trigger. Similar to I think the conditional plugin

Upvotes: 0

Related Questions