Parameterized Build

This is still a very young feature, so feedback appreciated

Sometimes, it is useful/necessary to have your builds take several "parameters." Consider the following use case:

  • You set up a test job on Hudson, and it accepts a distribution bundle as a parameter and perform tests against it. You want to have developers do local builds and let them submit builds for test execution on Hudson. In such a case, your parameter is a zip file that contains a distribution.
  • Your test suite takes so much time to run that in normal execution you can't afford to run the entire test cycle. So you want to control the portion of the test to be executed. In such a case, your parameter is perhaps a string token that indicates that test suite to be run.

Defining Parameters

First, you need to define parameters for your job by selecting "This build is parameterized", then using the drop-down button to add as many parameters as you need.

There are different parameter types available, and it is extensible, too. The way parameters take effect is also different depending on the parameter type you choose.

String parameter

String parameters are exposed as environment variables of the same name. Therefore, a builder, like Ant and Shell, can use the parameters. Continuing the above example, the following is a simple example:

  1. Reference parameter by name in builder. I'm using the "env" command to show the variable, followed by an echo statement to demonstrate referencing the value:
  2. Run build and observe output toward the bottom of the log (some vars removed for security and brevity):
    started
    [workspace] $ /bin/sh -xe /opt/apache-tomcat-6.0.14/temp/hudson20854.sh
    + env
    BAR=bat
    ...
    [workspace] $ /bin/sh -xe /opt/apache-tomcat-6.0.14/temp/hudson20855.sh
    + echo the value of bar is bat
    the value of bar is bat
    finished: SUCCESS
    

Ant works equally well. In the Properties section of the Ant builder, define a build property like:

my.prop=${env.BAR}

Note that because of the case sensitivity difference of environment variables in Windows and Unix, all the environment variables added by parameters are in upper case.

File parameter

File parameter allows a build to accept a file, to be submitted by the user when scheduling a new build. The file will be placed inside the workspace at the known location after the check-out/update is done, so that your build scripts can use this file.

Define Custom Parameter Types

A plugin can define custom parameter types. See ParameterDefinition for the starting point.

Launching a build with parameters

A build can be started just by accessing

http://server/job/myjob/buildWithParameters?PARAMETER=Value

To use this properly with wget, you need to quote the URL.
Apparently the parameter delay=0sec can be used.

Limitations

Currently the following are the known problems:

  • When build triggers are used to start a build, there's no way to pass parameters. This includes SCM polling, downstream builds, and periodic builds.

Open issues

How can i pass the configured parameter to the maven execution of the build?
E.g. I've got a maven build and a specific profile should be given as a String parameter in the hudson build.

Labels

  Edit Labels
(None)
  1. Aug 19, 2008

    Cees Bos says:

    How can I trigger a build based on a url? This is the url without a parameter:

    How can I trigger a build based on a url?

    This is the url without a parameter: http://localhost/hudson/job/jobname/build?delay=0sec (http://localhost/hudson/job/jobname/build)

    Can I add parametername=value? I tried it, but it didn't work. In this example http://localhost/hudson/job/jobname/build?delay=0sec&BAR=FOO\\

    1. Feb 27

      Thomas Guieu says:

      It works for me, if you "download" the URL with a WGETlike, don't forget to quot...

      It works for me, if you "download" the URL with a WGET-like, don't forget to quote this URL.

  2. Sep 15, 2008

    Gregoire Henry says:

    Windows Users : use my.prop=%BAR%  in ant properties as value expansion see...

    Windows Users : use my.prop=%BAR%  in ant properties as value expansion seems to be made by the OS ......

    1. Dec 09, 2008

      Stefan Baramov says:

      Linux Users: my.prop=$BAR since the same applies for Linux users as well. Or...

      Linux Users:

      my.prop=$BAR

      since the same applies for Linux users as well. Or at least in the 1.262 version.

  3. Sep 17, 2008

    Joel F says:

    It seems that if a parameter is in a downstream job, the parameter is not set. I...

    It seems that if a parameter is in a downstream job, the parameter is not set.
    It would be useful to pass parameters to downstream jobs, if they share the same named parameters.

    1. Oct 13, 2008

      Yoon Kyung Koo says:

      I also think so. I need to build each svn branches, and there's no easy way to b...

      I also think so.

      I need to build each svn branches, and there's no easy way to build downstream the branched modules.

  4. Sep 18, 2008

    Lukas Rytz says:

    A question related to the one by Cees Bos: is it possible to specify build param...

    A question related to the one by Cees Bos: is it possible to specify build parameters when using the "build periodically" feature?

    There is no other way to parametrize a build, right?

  5. Jan 07

    Ricardo Oliveira says:

    I believe that it would be very useful if the Build Parameters would also work f...

    I believe that it would be very useful if the Build Parameters would also work for multi-configuration projects.

  6. Feb 10

    Igor says:

    It would be great to be able to add not only parameter name and value but also s...

    It would be great to be able to add not only parameter name and value but also specify some description as well, so when user click on ''Build Now" button the parameterized page would give more helpful info about required parameters. 
    Also in my company we are using mostly boolean based parameters, it would be very useful to add one more type of parameters - Boolean (as a checkbox).

  7. Mar 31

    Sathish Sathyan says:

    Is there a way where I can pass multiple default values to a single parameter an...

    Is there a way where I can pass multiple default values to a single parameter and then select the value of the parameter from a dropdown (which has the default values), and then run the build?

    Seems to be a nice feature to have

  8. May 18

    Lars Skjærlund says:

    Is there a way to access the parameters from the project configuration page? If...

    Is there a way to access the parameters from the project configuration page?

    If I have a parameter called "Release" holding the release number, it might want to create a custom workspace called "C:\Hudson\Release-$Release" - but this doesn't work. It would be nice to have access to the parameters for use in the project configuration as well.

    BTW: Checking out "<long path>/release/$Release" from Subversion does work, though - very nice, indeed.