Using a matrix build with dynamic axis values (or looping in Jenkins)

1,775 views
Skip to first unread message

Hila Peleg

unread,
Sep 25, 2011, 10:39:49 AM9/25/11
to jenkins...@googlegroups.com

I want to use Matrix Build in order to run the same build once for each line in a configuration file (from SCM).

 

So far, I’ve tried using the GroovyAxis plugin to read the file, and also passing the axis values as parameters to the build. Neither worked, and the GroovyAxis script seems to run the script during save instead of the initialization of the buid.

 

Is there a way to dynamically set an axis’s values? And if not, what’s the recommended way for this sort of looping?

 

Cheers,

Hila

 

danny staple

unread,
Sep 26, 2011, 2:11:32 AM9/26/11
to jenkins...@googlegroups.com
Could you perhaps make the line to run a parameter for a normal
free-style build, and then set up a kicker job that uses the remote
access url to kick off the job with the parameter for each line?

--
Danny Staple

Director, ODM Solutions Ltd
w: http://www.odmsolutions.co.uk
Blog: http://orionrobots.co.uk/blog1-Danny-Staple

Hila Peleg

unread,
Sep 26, 2011, 5:25:34 AM9/26/11
to jenkins...@googlegroups.com
I do that in one place (using a Groovy system script) but then the upstream job loses track of the success or failure of the job I triggered. Since I'm basically re-launching the same build over and over again, the reporting becomes nightmareish if I can't at least connect the success/failure to the launch.

Stuart Sierra

unread,
Sep 26, 2011, 8:31:38 AM9/26/11
to jenkins...@googlegroups.com

Hi,

I did something similar by generating the job configuration files from a script. It's not hard, you can just copy the config.xml from the job directory and insert lines as needed. The downside is that you have to click "reload configuration from disk" after running the script.

My code (link below) is in Clojure, but the same technique works in any language.

Http://github.com/clojure/build.ci

Good luck,

Stuart Sierra
Clojure.com

-- ma...@stuartsierra.com

Mark Waite

unread,
Sep 26, 2011, 9:25:37 AM9/26/11
to jenkins...@googlegroups.com
If you're willing to construct job definitions "on the fly" like this, then you can use the command line interface "create-job" command to construct the job from the XML file and not have to use "Reload configuration from disk".

The command I use is something like:

java -Djava.net.preferIPv4Stack=true -jar jenkins-cli.jar -s http://127.0.0.1:8080/ create-job MyJobName < MyJobNameDefinition.xml


More documentation on the command line interface is available at


Thanks,
Mark Waite



From: Stuart Sierra <ma...@stuartsierra.com>
To: jenkins...@googlegroups.com
Sent: Monday, September 26, 2011 6:31 AM

Subject: Re: Using a matrix build with dynamic axis values (or looping in Jenkins)

Steve Roth

unread,
Sep 26, 2011, 9:28:40 AM9/26/11
to jenkins...@googlegroups.com, Stuart Sierra
I've done something similar (though not for looping).

If you use curl with the Jenkins REST API (to create or update), then you don't have to click Reload. 
NOTE: I have seen issues when a job which is currently running is being updated, so before using the REST API to update a job, I first make sure it is not running.

-Steve

Hila Peleg

unread,
Sep 26, 2011, 12:10:23 PM9/26/11
to jenkins...@googlegroups.com

I’ve finally managed to do just what I want, so I’ll share:

 

I’m using the Groovy System Script task to read the file, and then the following snippet:

 

def build = Thread.currentThread().executable //Get current build

new File(dir,filename).eachLine{line->

          def fut = hudson.model.Hudson.instance.getItem("my_test").scheduleBuild2(

                           0,

                           new hudson.model.Cause.UpstreamCause(build),

                           new hudson.model.ParametersAction(new hudson.model.StringParameterValue("param1",param1_value),new hudson.model.StringParameterValue("param2",param2_value))

           )

          def gotten = fut.get() //This returns when fut.isDone()

         println gotten.getUrl() + ': ' + gotten.result

          if (gotten.result.isWorseThan(build.result) ) {

                build.result = gotten.result //Set this build’s result to worst child build result

          }

}

 

From: jenkins...@googlegroups.com [mailto:jenkins...@googlegroups.com] On Behalf Of Steve Roth
Sent: יום ב 26 ספטמבר 2011 16:29
To: jenkins...@googlegroups.com
Cc: Stuart Sierra
Subject: Re: Using a matrix build with dynamic axis values (or looping in Jenkins)

 

I've done something similar (though not for looping).

Reply all
Reply to author
Forward
0 new messages