Skip to end of metadata
Go to start of metadata

Plugin Information

Distribution of this plugin has been suspended due to unresolved security vulnerabilities, see below.

The current version of this plugin may not be safe to use. Please review the following warnings before use:

Jenkins Groovy Axis Plugin

Description

This plugin allows to have scriptable axes for Matrix Jobs. Groovy is the scripting language being used.

The script will have to return a list of strings and each of the strings will be an element of the axis.

If the script does not return a list of strings then

[default]

will be returned instead.

Examples

Define an axis with three values:

return [ "Axis1", "Axis2", "Axis3" ]

Define the same axis programmatically:

def result = []
(1..3).each {
   result += "Axis"+it
}
return result

Define an axis whose values are the files in the root directory:

def dir = new File('/')
def result = []
dir.eachFile {
   if (it.isFile()) {
      result += it.canonicalPath
   }
}

return result

Screenshot

14 Comments

  1. Is it possible to include environment variables in the groovy script? I'd like things such as file paths to be dynamic...

    1. Just use : System.getenv("YOUR_ENV")

      1. Hi,

        I am trying to create axis to deploy some content to choosen to all selected environments.

        The idea is to setup "This build is parameterized" -> create booleans: QA_SERVER1, QA_SERVER2, QA_SERVER3

        And if user select for example QA_SERVER1 & QA_SERVER3 it should execute only for this servers.

        I wrote script (not only , but to understand my logic), but it not working.

        How should I rewrite it to access custom booleans?

        import hudson.model.*
        def result = []
        
        if ( System.getEnv('QA_SERVER1') == true ) {
        result += 'qaserver1.domain.com'
        }
        if ( System.getEnv('QA_SERVER2') == true ) {
        result += 'qaserver2.domain.com'
        }
        if ( System.getEnv('QA_SERVER3') == true ) {
        result += 'qaserver3.domain.com'
        }
        return result
        
  2. Ouch, this was not as dynamic as I hoped. The groovy script doesn't seem to be run for each build. It is only run when pressing Save/Apply in the project configuration. Could that be changed somehow? I have matrix values stored in files and I want them to be reread for every build.

    1. There's a pull request in Jenkins core to address this issue.

      1. Unknown User (maerkus)

        I upgraded Jenkins to 1.472, which according to changelog has this feature implemented. Do I need to modify now something to actually get it working, as my axis definition updates still only when I apply/save job settings.

        My axis is simple groovy script reading axis definition from a text file on web server as follows;

        def url = "http://www.domain.com/testsets.txt".toURL()
        def testsets = []
        url.withReader { reader ->
          reader.eachLine { line ->
            testsets += line
          }
        }
        return testsets
        
  3. Is it possible to include build parameters in the script?  For example, I could have another job pass in a list of Linux .config files and build a kernel for each.

  4. I'm trying to trigger matrix jobs on all nodes of particular type. Since there are lots of configured nodes and some of them can be offline the plugin seems to be a natural choice. However, the things doesnt seem to work. The expression for axis values is

    def result = []
    jenkins.model.Jenkins.instance.nodes.each {
        if (it.toComputer().online && it.assignedLabels.contains(new hudson.model.labels.LabelAtom("linux"))) {
            result += it.name
        }
    }
    return result
    

    It correctly determines node names: [ superfrog1, pintov1, pintov2, swtsscg, gdrcw, pintov4, pecanv6 ]

    However, when build is executed then things go wrong as Jenkins doesnt seems to be using axis values at all:Building remotely on swtsscg in workspace /ci/workspace/test/node/superfrog1
    superfrog1 $ /bin/sh -xe /tmp/hudson5253422839681441452.sh
    Label is superfrog1
    Executing on swtsscg

    So while axis label was superfrog1 build was executed on node stwsscg. Any suggestions?

  5. Here's how to do it with build parameters, according to https://github.com/jenkinsci/groovyaxis-plugin/commit/945518d9c2b35376f9ddf8b72e71a7aeec65b9e8 :

    def value = ""
    if (context != null) {
      def resolver = context.build.buildVariableResolver
      value = resolver.resolve("AXISVALUES")
    }
    return value.split() as List
  6. I see the same behavior as Nickolay.  Jobs with the discovered labels are executed, however they actually run on the wrong nodes.  Has anyone looked into it?

    I would love to get this plugin working!

    1. This change fixes it for me (extend LabelAxis instead of Axis).  I made my own fork of this plugin called GroovyLabelAxis which solves it nicely.  Including ernstp's parameters option this givesreally nice functionality of choosing labels for the axis at job runtime

      public class GroovyLabelAxis extends LabelAxis {
      ...
      
      1. Cosmo,

        Have you published this fix anywhere? I am running into the same problem

        Thanks.

  7. I configure so that the Axis amount depended on the parameter build. But there is a problem:

    let's build A has started 20 Axis and the next build  B- 10. At the matrix A will be showed only 10 Axis icons and links. Is it possible to display the Axis as much as was used in the build?

    1. You can spawn full matrix and then selectively skip configurations you are not interested in. You can colorize "skipped" builds and even add badges and explanations to them. Decision to skip is just a first step in the build. Could be groovy or shell. Groovy postbuild plugin can be used to check if build was skipped  and colorize result for this configuration.