Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I chain a manually triggered downstream job, also passing parameters?

I am using Jenkins to create a build pipeline, and need to trigger a deployment step in the pipeline. This means a manual process (the build occurs automatically, timed, then stops at the deployment stage, waiting for manual authorization).

I need the deploy step to also be triggered with parameters from the prior step.

So, using the 'Parameterized plugin' I can pass parameters between jobs. I can trigger automated OR manually triggered downstream jobs (not sure if this is a standard feature, or manual builds was added by some plugin).

However, I cannot find any way to trigger a manual parameterized job.

Does anyone know of a way to do this? Is there another plugin I can use?

The reason I need the parameters is that I have created a generic deployment job, and need to pass in the module name, and maven version to deploy. I could create specific deployment jobs for each module, but this would be very painful.

I have also been considering the following, but it seems a kludge:

  1. Automated job performs build, triggers 'deployment trigger' build, passing parameters.
  2. 'Deployment trigger' writes these parameters to a file on the filesystem (build step - shell execution), and manually triggers the actual deployment job
  3. Deployment job (MUST use the WORKSPACE from the 'deployment trigger' job) reads parameters from the filesystem (using EnvInject plugin).

There are various problems with this approach

  1. I just don't like it.
  2. Has an intermediate jobs just to pass parameters. This clutters the Jenkins workspace
  3. As builds are performed on the same WORKSPACE, seems fragile to me (though workable!)
like image 711
GKelly Avatar asked Aug 16 '12 09:08

GKelly


2 Answers

Current production version (1.4.2) of build-pipeline-plugin allows it - to specify manual downstream job with parameters, which is displayed on the pipeline and can be started from there. Old versions couldn't do it.

like image 145
Ivan Avatar answered Sep 21 '22 18:09

Ivan


Take a look at the Build Pipeline Plugin: https://wiki.jenkins-ci.org/display/JENKINS/Build+Pipeline+Plugin.

You can specify jobs to be automatically triggered or manually triggered.

Also if you need parameter passing between jobs you will need to download the Groovy Plugin: https://wiki.jenkins-ci.org/display/JENKINS/Groovy+plugin

In order to pass parameters lets say an SVN revision between jobs you will need to Execute System Groovy Script at the start of your build. This is an example that will add a SVN_UPSTREAM parameter that can be used by any downstream jobs. NOTE: I have noticed a problem with creating a downstream job that also has a system groovy script. It seems to blow away any references to the original parameters created.

import hudson.model.*
def build = Thread.currentThread().executable;
build.addAction(new ParametersAction(new StringParameterValue("SVN_UPSTREAM", build.getEnvVars()['SVN_REVISION'])));
println "SVN_UPSTREAM:" + build.getEnvVars()['SVN_UPSTREAM'];
like image 21
user1687178 Avatar answered Sep 20 '22 18:09

user1687178