Skip to main content

Create a Matrix-like flow with Pipeline

Comments

2 comments

  • Michael Fowler

    An example for declarative would be nice

    0
  • Allan Burdajewicz

    Michael,

    For declarative, you would need to rely on the script { ... } block at the moment. So the solution is similar:

    def getTasks(axisNodes, axisTools) {
    def tasks = [:]
    for(int i=0; i< axisNodes.size(); i++) {
    def axisNodeValue = axisNodes[i]
    for(int j=0; j< axisTools.size(); j++) {
    def axisToolValue = axisTools[j]
    tasks["${axisNodeValue}/${axisToolValue}"] = {
    node(axisNodeValue) {
    def javaHome = tool axisToolValue
    println "Node=${env.NODE_NAME}"
    println "Java=${javaHome}"
    }
    }
    }
    }
    return tasks
    }

    pipeline {
    agent none

    stages {

    stage("Before") {
    agent any
    steps {
    echo "before"
    }
    }

    stage("Matrix") {
    steps {
    script {
    def axisNodes = ["osx-agent-1","osx-agent-2"]
    def axisTool = ["jdk7","jdk8"]
    parallel getTasks(axisNodes, axisTool)
    }
    }
    }

    stage("After") {
    agent any
    steps {
    echo "after"
    }
    }
    }
    }

    Regards,

    0

Please sign in to leave a comment.

About CloudBees Support

Our Support Engineers are available to help with any questions or problems you may have with any of our products.