Jenkins Pipeline Multi-Configuration Project

Initial situation:

I have a job in Jenkins that works with ant script. I easily managed to test this ant script on more than one version of the software using a "project with multiple configurations."

This type of project is really cool, because it allows me to specify all versions of the two programs that I need (in my case, Java and Matlab), and it will run my ant script with all my options combinations.

These parameters are then used as a string to concatenate in the location of the executable that my ant will use.

example: env.MATLAB_EXE = / usr / local / MATLAB / $ {MATLAB_VERSION} / bin / matlab

This works fine, but now I am porting these scripts to its version.

Pipeline Migration:

I managed to implement the same script in the pipeline using Parametrized pipelines pluin. With this, I reach a point where I can manually select which version of my software will be used if I run the assembly manually, and I also found a way to accomplish this by periodically selecting the option that I want each time I start.

This solution seems to be quite workable, but is not really satisfactory.

In my project with several configurations, there was a function that does not do this:

  • With more than one parameter, I can adjust the interpolation and execute each combination
  • The tasks are clearly separated, and in the assembly history / assembly details it is easy to find out which settings were used
  • ""

, , , .

: jenkins, ?

+4
2

, , , ...

/, , , .

- . , .

: OPS , . Groovy, , , , , , , , , , .

, matrixBuilder , . . , .

matrixBuilder . (, ).

/*
    All the config axes are defined here
    Add as many lists of axes in the axisList as you need.
    All combinations will be built
*/
def axisList = [
    ["ubuntu","rhel","windows","osx"],           //agents
    ["jdk6","jdk7","jdk8"],                      //tools
    ["banana","apple","orange","pineapple"]      //fruit
]



def tasks = [:]
def comboBuilder
def comboEntry = []


def task = {
    // builds and returns the task for each combination

    /* Map the entries back to a more readable format
       the index will correspond to the position of this axis in axisList[] */
    def myAgent = it[0]
    def myJdk   = it[1]
    def myFruit = it[2]

    return {
        // This is where the important work happens for each combination
        node(myAgent) {
            println "Executing combination ${it.join('-')}"
            def javaHome = tool myJdk
            println "Node=${env.NODE_NAME}"
            println "Java=${javaHome}"
        }

        //We won't declare a specific agent this part
        node {
            println "fruit=${myFruit}"
        }
    }
}


/*
    This is where the magic happens
    recursively work through the axisList and build all combinations
*/
comboBuilder = { def axes, int level ->
    for ( entry in axes[0] ) {
        comboEntry[level] = entry
        if (axes.size() > 1 ) {
            comboBuilder(axes[1..-1], level + 1)
        }
        else {
            tasks[comboEntry.join("-")] = task(comboEntry.collect())
        }
    }
}

stage ("Setup") {
    node {
        println "Initial Setup"
    }
}

stage ("Setup Combinations") {
    node {
        comboBuilder(axisList, 0)
    }
}

stage ("Multiconfiguration Parallel Tasks") {
    //Run the tasks in parallel
    parallel tasks
}

stage("The End") {
    node {
        echo "That all folks"
    }
}

http://localhost: 8080/job/multi-configPipeline/[build]/flowGraphTable/ ( " " .

: "", , , .

...
return {
    // This is where the important work happens for each combination
    stage ("${it.join('-')}--build") {
        node(myAgent) {
            println "Executing combination ${it.join('-')}"
            def javaHome = tool myJdk
            println "Node=${env.NODE_NAME}"
            println "Java=${javaHome}"
        }
        //Node irrelevant for this part
        node {
            println "fruit=${myFruit}"
        }
    }
}
...

node stage .

, ( ). comboEntry . , , , , , , . tasks[comboEntry.join("-")] = task(comboEntry.collect()).

, stage ("Multiconfiguration Parallel Tasks") {} . . , , . , "" .

, " " , - , . , .

, , , , . "" , ( ) "", . , .

+6

1 3 , , "", "" Pipeline, , , - , , . ( "" "" ) .

2 , . , , , Blue Ocean, , . JENKINS-27395 , .

+1

Source: https://habr.com/ru/post/1687010/


All Articles