26

I have a build job and a test job parameters.

I want to be after the build job, simultaneously run test job with one parameter and the same test job with different parameters in parallel execution.

                build job  
                   |  
                  / \  
         test job    test job
   with one params    with other params
            |             |

How to accomplish this and whether it is possible to perform without having to write your own plugin?

Thanks!

Maksim Kolchin
  • 517
  • 1
  • 7
  • 17

7 Answers7

21

When you create your test job, create it as a "Build multi-configuration project" While configuring the job select "Configuration Matrix" then "User-defined axis"

You can use the name of this axis as a parameter in your job. the given parameters will be started simultaneous in different jobs. (if enough executors are available)

HenkI
  • 226
  • 2
  • 3
  • 2
    it will be great, if you can define a little bit more about how to achieve the same thing, as i am also trying to achieve the same thing – Monis Majeed Sep 22 '16 at 11:34
2

Playing off @Soo Wei Tan's answer, I found the following works well.

  • Parameterized Trigger Plugin
  • Choose "Parameter Factory"
  • Choose "For every property file, invoke one build"

Then, in a shell, write a series of property files, and the Trigger Plugin will take care of the rest.

You can even combine this with a matrix style job at the top level in interesting ways. For example, triggering on the user-defined axis, keeping track of it all with a grid. Really quite a flexible approach, if a bit hidden.

dpb
  • 1,205
  • 2
  • 9
  • 20
2

I had the same requirement, and found that Parameterized Trigger Plugin was not flexible enough for passing different parameters to different (or the same) jobs in parallel. Yes you can use a Parameter Factory with property files, but that would mean adding new property files to my version control solely for the purpose of configuring Jenkins. A Multi-Configuration project with a configuration matrix also seemed overcomplicated.

The better and more straightforward solution for me was the Multijob Plugin, which has the concept of Phases. A MultiJob can have multiple phases. Phases run sequentially and jobs within a phase will run concurrently (in parallel).

After installing the MultiJob plugin, when creating a new Jenkins item, select MultiJob Project. You can then create one or more phases. Each job within a phase has it own parameters, click Advanced... -> Add Parameters

Also it is very easy to configure what should happen if a particular job fails, should the entire MultiJob continue or fail etc, see the Kill the phase on: and Continuation condition to next phase when jobs' statuses are: settings.

For me this was much more intuitive to use than the Parameterized Trigger Plugin or a Mult-Configuration project, and did not require any extra configuration outside of Jenkins.

ptha
  • 836
  • 1
  • 8
  • 22
  • But would force us to create a copy of same job twice within a phase. I have exact same requirement but i am not able to find a option of passing date dynamically. I need to run same job simultaneously for dates 1-15 & 16-30/31 – AJm Jul 27 '18 at 22:09
  • @AJm Yes you would call the same job twice within the same phase with different parameters. You would need to configure the job to run be able to run concurrently (can it be run concurrently safely?). There is a checkbox **Execute concurrent builds if necessary** in the Jenkins job configuration. I'm not sure what you mean about _passing the date dynamically_ it's possible this could be achieved with the [Jenkins Job DSL API](https://jenkinsci.github.io/job-dsl-plugin/) but it might be best to open a specific question with more details. – ptha Aug 23 '18 at 16:50
1

Assuming you know the parameters when you are finishing your build job, you can use the Parameterized Trigger Build plugin to fire both downstream jobs with different parameters.

Soo Wei Tan
  • 3,262
  • 2
  • 34
  • 36
  • I know about this plugin, but it will not start same job twice. I tested it several times. – Maksim Kolchin Apr 12 '11 at 07:14
  • How about launching 2 separate jobs via the [API](http://wiki.hudson-ci.org/display/HUDSON/Remote+access+API) using curl? – Soo Wei Tan Apr 12 '11 at 18:11
  • You can create a dummy job which just passes the parameters through to your test job. It would be a nasty work around, but will work. If you want to to something after the test job you can also use the join plugin. Theoretical it should support your use case. – Peter Schuetze Apr 15 '11 at 11:51
0

One option would be to use Build Flow plugin (https://wiki.jenkins-ci.org/display/JENKINS/Build+Flow+Plugin) potentially together with Job DSL plugin (https://wiki.jenkins-ci.org/display/JENKINS/Job+DSL+Plugin). You can use Job DSL to define job steps that invoke your build with different command line arguments and orchestrate the build with Build Flow.

hgrey
  • 3,033
  • 17
  • 21
0

I have a slightly different use case. We have test jobs that run against our main build during the development cycle. Toward the end of the cycle; we create a release candidate build and run the same tests against that. We want to also continue testing the main build.

               Main Build     Release Build
                         \   /
                           |
                       same set of tests

I can create duplicate jobs with just different names to handle this. But there have to be a more elegant/simpler way.

  • This is really a separate question. But one simple way is for your parent jobs to pass an "environment" parameter to the downstream job(s) which then behave differently based on the parent. – Steven the Easily Amused Nov 17 '16 at 20:42
  • In this scenario, Different parameter and accessing same job at same time, which option will suites for running ? because I am using freestyle job. – Shankar Dec 22 '20 at 23:28
-2

Could you please say a bit more why do you need your test jobs to run concurrently?

I do use test that need to split and run simultaneously, but I use a single Jenkins/Hudson job that has a weight > 1 (see Heavy Job Plugin).

datka
  • 860
  • 2
  • 11
  • 15
  • I have a build job that produce several packages. For each of the packages I want start a parametrized test job that is same for all the packages, but only the parameters of the jobs will change. – Maksim Kolchin Jun 06 '11 at 17:15