Jenkins trigger build dependent on build parameters

核能气质少年 提交于 2019-12-13 02:11:49

问题


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

回答1:


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.




回答2:


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



来源:https://stackoverflow.com/questions/35344304/jenkins-trigger-build-dependent-on-build-parameters

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