Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I organize variant building of a parametrized job in Jenkins?

Tags:

jenkins

I have a parametrized job that takes a name, a SVN Repository and a shared directory. I need to call this job regularly with roughly 20 sets of these parameters. At the moment I just created 20 jobs and each calls the main job.

This is a very tedious configuration and clutters the main view in Jenkins.

Is there a better possibility to solve this? I am open to either restructure the jobs or use plugins to "hide" them.


More Details about the jobs: I have actually two kinds of main jobs:

  • a delivery job. We deploy our application to ~20 different shared directories. These jobs are configured to run once every night. (Trigger build periodically)
  • a computation job. This one computes data based on the svn repository and stores it in the shared directory. These jobs are configured to run every 15 minutes.
  • The jobs may and should run in parallel

What I need/want:

  • Sometimes it is needed that a developer needs to start one (or a couple) of the configurations manually
  • Something like the matrix configuration plugin could solve my problem. If it would be possible to somehow set my parameters as one axis, I would be happy
  • Multijob would be another close solution to my problem, unfortunately this 'bug' blocks me: JENKINS-39678
like image 719
Absurd-Mind Avatar asked Oct 30 '22 05:10

Absurd-Mind


2 Answers

Not allowed to comment, but @Absurd-Mind, it sounds like you wanted to build just one job in the beginning that fits all and blows up now. When you have about 20 different settings try to find a larger common basis or split them completely.

Also, we have also such a job.... old shell script crap and well, one of my colleagues build a multijob pipeline around it, that can run in parallel. Under MultiJob Phase you can set Job execution to parallel.

But be careful, if it contains a build tool like bower or so you can't as easily wipe the cache because they share one.

like image 73
Hoall Avatar answered Nov 15 '22 04:11

Hoall


You could use the Pipeline plugin and write groovy code to do this. You could add a bunch of checkbox input parameters, 1 for each set of parameters you want, and then conditionally execute the other job with that set of parameters.

image of build parameters with checkboxes

node: {
   stage ('set1') {
      if(env.build_set1) {
         build job: 'main_job', parameters: [[$class: 'StringParameterValue', name: 'name', value: 'Name1'], [$class: 'StringParameterValue', name: 'directory', value: 'dir1']]
      }
   }

   stage ('set2') {
      if(env.build_set2) {
         build job: 'main_job', parameters: [[$class: 'StringParameterValue', name: 'name', value: 'Name2'], [$class: 'StringParameterValue', name: 'directory', value: 'dir2']]
      }
   }
}

This example runs sequentially, but you can also make these jobs run in parallel.

like image 41
Nathan Hadzariga Avatar answered Nov 15 '22 06:11

Nathan Hadzariga