1
votes

I have a pipeline script that looks like this:

node {
  try {
    stage('Prepare') {
      // git clone here
    }
    stage('Compile') {
      sh "make ${build_type}"
    }
    stage('Test') {
      sh "./run tests ${build_type}"
    }
  }
  finally {
    if (fileExists("test_results.xml")) {
      junit "test_results.xml"
    }
    emailext subject: "Build finished",
      body: '${JELLY_SCRIPT, template="some-template.template"}',
      to: "some-one@somewhere"
  }
}

${build_type} can be "release" or "debug".

When my build receives a trigger, I want my pipeline to run once for every parameter in ${build_type} and then send me one email containing a report about both builds.

How can I achieve this?

I tried to define a parallel block inside the Compile stage and set build_type there, but this doesn't make the other stages to run in parallel.

1

1 Answers

1
votes

I hope the following snippet can help you. This way you can include multiple build types dev,qa,prod.

def build_types = "dev;qa"

node {
try {
      stage('Prepare') {
          // git clone here
      }

     def buildTypeVar = build_types.tokenize(';')

     for(int i=0;i<buildTypeVar.size();i++){

        buildType=buildTypeVar.get(i).trim()

         stage('Compile ${build_type}') {
             sh "make ${build_type}"
        }
        stage('Test ${build_type}') {
            sh "./run tests ${build_type}"
        }
    }

 }
 finally {
  if (fileExists("test_results.xml")) {
  junit "test_results.xml"
  }
  emailext subject: "Build finished",
    body: '${JELLY_SCRIPT, template="some-template.template"}',
    to: "some-one@somewhere"
 }
}