Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Update link to Jira issues

Wiki Markup
{jenkins-plugin-info:pluginId=groovy-label-assignment}
Excerpt

Provides "Groovy script to restrict where this project can be run" in job configuration pages.

...

  • You have to build a project for multiple platforms: arm, win, linux
  • There are following nodes:

    Node

    Label

    arm

    win

    linux

    win1

    vs2010,armcc

    O

    O

    X

    win2

    armcc

    X

    O

    X

    linux

    gcc

    X

    X

    O

You can manage this by using multi-configuration project as followings:

  • Define a User-defined axis "platform": arm, win, linux
  • Define a Slaves axis "slave": armcc, vs2010, gcc
  • Define "Combination Filter" as following:

    Code Block
    
    (platform == "arm" && slave=="armcc") || (platform == "win" && slave=="vs2010") || (platform == "linux" && slave=="gcc")
    

...

  • Define a User-defined axis "platform": arm, win, linux
  • Define "Groovy script to restrict where this project can be run":

    Code Block
    
    def labelMap = [
        arm: "armcc",
        win: "vs2010",
        linux: "gcc",
    ];
    return labelMap.get(binding.getVariables().get("platform"));
    

...

  • Parameterize the job.
  • Define a Boolen Value parameter "release", which specifies the triggering build is for release.
  • Define "Groovy script to restrict where this project can be run":

    Code Block
    
    return (release == "true")?"RELEASE":"!RELEASE"
    

...

  • Some variables may not be properly binded:
    • Some type of parameters may be not properly binded.
    • Environment variables of some type of plugins may be not properly binded.
    • This is for Groovy Label Assignment plugin works when a build is going to be created, and is not created. Parameters and plugins that refers build information does not work properly.
  • When Groovy Label Assignment plugin fails, a build is rejected silently. Failures happen in following cases. You can refer the system log to see why Groovy Label Assignment plugin failed.
    • Groovy script is not defined.
    • Groovy script contains syntax errors.
    • Groovy script failed at the runtime.
      • Especially in case referring non-binded variables. It often happens when running with multi-configuration project. In that case, you can access the variable safely as following:

        Code Block
        
        binding.getVariables().get("variable-name");
        
    • Returned value cannot be parsed as a label expression.

...

To report a bug or request an enhancement to this plugin please create a ticket in JIRA (you need to login or to sign up for an account).

Jira Issues
renderModestatic
columnstype;key;summary
width80%
anonymoustrue
urlhttp://issues.jenkins-ci.org/sr/jira.issueviews:searchrequest-xml/temp/SearchRequest.xml?jqlQuery=project+%3D+JENKINS+AND+status+in+%28Open%2C+%22In+Progress%22%2C+Reopened%29+AND+component+%3D+%27groovy-label-assignment%27

Also have a look on How to report an issue

Jira
serverJenkins JIRA
columnstype,priority,key,summary
maximumIssues20
jqlQueryproject = JENKINS AND status in (Open, "In Progress", Reopened, "In Review", Verified) AND component = 'groovy-label-assignment-plugin'
serverIddd058dce-0c66-3b77-8b09-71b1d7728747

How does this work?

This plugin works as following:

  1. When a new build is triggerd, GroovyLabelAssignmentQueueDecisionHandler is called.
  2. If GroovyLabelAssignmentProperty is assigned to the job, call it.
  3. EnvironmentContributingAction#buildEnvVars() is called for retrieving variables to bind to the Groovy script.
    • Parameters are defined here.
  4. Retrieve axes values configured to that job and bind to the Groovy script.
  5. Run Groovy script.
  6. Parse returned value as a label expression.
  7. Assign it with LabelAssignmentAction.

Change Log

Version 1.2.0 (May 8, 2016)

  • Now targets Jenkins 1.509 and later (was 1.466).
  • Groovy scripts run with Script Security Plugin (JENKINS-27535)
    • Existing scripts are configured to run in the Groovy sandboxes.
    • You may have to approve some methods to allow run in the sandbox, or approve your scripts to allow run out of the sandbox.
    • See Script Security Plugin for details.

Version 1.1.1 (Sep 13, 2015)

  • Fixed: fails to find nodes with a specified label when the label is once removed from all nodes (JENKINS-30135)

Version 1.1.0 (Mar 21, 2015)

  • Expose current Jenkins job to the Groovy script as "currentJob" variable (JENKINS-27424)

Version 1.0.0 (Jun 05, 2013)

  • Initial release.