Wednesday 8 August 2018

jenkins continuous integration: most useful methods for jobs to trigger other jobs

Jenkins has quite a flexible choice of methods for jobs that need to interact with one another. 
There is a built in "Post-build Action: build other projects" and there are a couple of plugins which can be used. The "Post-build Action: build other projects" is probably most suitable. And the "Lockable Resources Plug-in" can be used to make the jobs mutually exclusive.
* SIMPLEST METHOD "Post-build Action: Build other projects" *
  1. Install Lockable Resource plugin and add a lockable resource "stream1" and configure jobs stream1_build and stream1_test1 to lock on that resource.
  2. Configure the stream1_build job, Add "Post-build Action: Build other projects" Build job stream1_test1 if the build job is Stable.
You can chain multiple jobs together in a pipeline or stream like this. 

* LIST of useful built-ins and plugins: *
It is also useful to use FSTrigger plugin, build jobs or other jobs may generate logs or image files or test reports. Jobs can be triggered to run when these files or directories appear or are updated. Jobs in remote jenkins or external to jenkins can be used to trigger jobs using this method.
  1. Built in Post-build Action: Build other projects
    * Trigger only if build is stable   
    * Trigger even if the build is unstable 
    * Trigger even if the build fails   
    
  2. BuildResultTrigger Plug-in - This plugin makes it possible to monitor the build results of other jobs. Similar to "Post-build Action: build other projects" only at top of job config as a trigger with cron schedule.
  3. Filesystem Trigger Plug-in - The plug-in makes it possible to monitor changes of a file or a set of files in a folder.
  4. Parameterized Trigger Plug-in (which adds Post-build Action: Trigger parameterized build on other projects) Similar to "Post-build Action: build other projects but convenient to pass build information e.g. in parameters.ini style file or boolean or other params from one job to another.
  5. Lockable Resources Plug-in This plugin allows to define external resources (such as printers, phones, computers) that can be locked by builds. If a build requires an external resource which is already locked, it will wait for the resource to be free.
I came across this older question "Jenkins: Run only if other job is cleanwhich did not have good answers. As I said in my preamble to answer it took a while for me to discover how to use these methods, surprising as "Post-build Action: build other projects" is built in. It is easy to overlook.

No comments: