Jenkins Parameterized Trigger Plugin

Jenkins

If you’re using Jenkins for automation in software development, you may have a need to do a post-build action that passes information from the original build to the next action.

For example, say you execute one script with date and time information and upon successful completion, you want to then execute another script sending over the same date and time information.  There is a Parameterized Trigger Plugin that helps you to do exactly that.  Implementation of the plugin to actually pass parameters from one job to the next, however, isn’t exactly clear from the plugin documentation.  It took some messing around with the plugin on both jobs to figure out how things work.  I figured I might save someone a few hours of time trying to figure it out.

  • First, on the original job, in the “Execute shell” section, save off your parameters to a text file.  The following example will save the current date and the previous hour in the Command area like so:

DATE=$(date +%Y-%m-%d)
HOUR=$(date -d “1 hour ago” +%H)
echo “JOB_DATE=$DATE
JOB_HOUR=$HOUR” > job_parameters.txt

  • Then add a post build action to trigger a parameterized build on other projects.  In the “Build Triggers” section, give the name of the project you wish to execute upon completion of the current script.  If you only want to run the next script on successful completion of the original script, make sure you change the “Trigger when build is:” to stable.
  • Next, in the Build Triggers section, select Add Parameters -> Parameters from properties file. Fill in “Use properties from file” section with the file name you saved the parameters to in the “Execute shell” section above.  You also probably wish to check the “Don’t trigger if any files are missing” option.
  • Now save that project and select the downstream project to configure.
  • Specifically check the “This project is parameterized” in your downstream project.  For each parameter you’ll need to “Add Parameter” and put the same name you defined in the original project.  For our example, we would add 2 parameters with the names JOB_DATE and JOB_HOUR respectively.
  • You are now free to use your parameters in the Build section of your downstream project to your heart’s content!  For example, an execute shell command:

docker run -t –rm ‘your_docker_image’ –date=${JOB_DATE} –hour=${JOB_HOUR}

Be the first to comment on "Jenkins Parameterized Trigger Plugin"

Leave a comment

Your email address will not be published.


*