rss

How to Jenkins : chain jobs with parameters

This post describes How To chain jobs with parameter(s).
- Choose optionA if you're using pipeline plugin.
- OptionB is a little bit deprecated, but usefull if you would like to script your build execution or trigger it remotely.

(option A) Define a post action in first job

First recommended and simple way if your are using "Build Pipeline". Go to the first job configuration to append a post-action :

(option B) Chain it using shell scripts


NB: this option will make loosing your pipeline chain.
I recommend to use 2 small dedicated temp jobs to test it first. That would avoid to run unnecessarely long build...

Steps :
  • Install Build Token Root Plugin
  • Define first job with parameter
  • Define second job ("follower") with parameter
  • Define a trigger for the follower
  • Append a shell script to chain the two jobs
  • Try!

Install Build Token Root Plugin

Ask to your Jenkins administrator to install this plugin : Build Token Root Plugin
Wait that Jenkins reboot (required).

Define first job with parameter

Add "branch" parameter to your first job.

Add a shell script to echo the variable.

Define follower job with parameter

Add "branch" parameter to your second job (same as previously).
Add a shell script to echo the variable(same as previously).

Define a trigger for the follower

Add a trigger for the second job. Set a secret token here.

Append a shell script to chain the two jobs

Open the first job configuration to add the following shell script.
You will need to adapt the jenkins host value corresponding to your environment.

# show job parameter
echo branch=${branch}

#  resources
#  https://wiki.jenkins-ci.org/display/JENKINS/Parameterized+Build
#  https://wiki.jenkins-ci.org/display/JENKINS/Build+Token+Root+Plugin
#  http://curiositedevie.blogspot.nl/2016/02/how-to-jenkins-chain-jobs-with.html
export JENKINS_HOST=https://myjenkins.domain.net
export JOB_TOKEN=THISISWONDERFULL
export JOB_NAME=git_config_follower
export JOB_PARAM1=branch=${branch}
export JOB_CAUSE=Launching_follower_with_branch_set_to_${branch}
export JOB_PING="$JENKINS_HOST/buildByToken/buildWithParameters?job=$JOB_NAME&token=$JOB_TOKEN&$JOB_PARAM1&cause=$JOB_CAUSE"
echo $JOB_PING
curl --verbose --insecure $JOB_PING

Try!

Launch the first job with a parameter.

Go to the Job console to check curl http status.
Go to the follower (second) job logs.
Check the follower result!

Aucun commentaire:

Enregistrer un commentaire

Mots clés du blog

acceptancetest androï Android androïd Android7 api appender appengine application applications archive array assistantematernelle astuce auth0 authentication authority automation Axis bash bearer blog bower build bundle c calendrier camille combal cdi certificate cf client cloudfoundry collaboratif command commandes connexion console css démasquées démasquer développement dll dump easter eggs écologie écrit employeur EMUI EMUI5.0 enfant évènement export-package ExtJS fiche find firefox gadget gelf gem git gmail gooelappengine google gparted gps graylog grenoble Grid gui harddrive heroku hover howto HTML http https IE ihm immobilier imprimante innovation insolite instance integration Java JavaScript jenkins jeu jobs json json-schema-validator key keystore labs linux livre log log4j logger logs lombok masquées masquer maven maven-gae-plugin Mémoire microsoft mobile mockito mondialisation monitor MUSE musique en ligne myopera nodejs npm NT NTEventLogger onglet openstack osgi paas package parameters parent php politique prosyst prototype proxies proxy quartz radio rappel recherche regex repository resize RIA rock route ruby rubygems s8500 samsung scheduler scm sel selenium Serializer server shared shell slf4j smartphone so société song spy ssh ssl struct swagger swig tâches téléphone téléréalité test thunderbird timeout token Tomcat tooltip tooltips truststore ubuntu unit test validator virgin virtualbox wave waze web WebApp wiki wikimedia wikipédia wikipen windows yahoo youtube yum