3

Managed to successfully run integration tests in parallel on the same node and I now I would like to distribute them across different nodes. In the example below I want stages IT 1 and IT 2 to run on different nodes leaving IT 3 to run on the original node. Tried several combinations by using node as a parent of stage('IT 1') and node as a child but I get syntax errors for both. What is the proper syntax to achieve this?

pipeline {

  agent { label '!master' }

  stages {
    stage('Integration Tests') {
      parallel {
        stage('IT 1 (slow)') {
          steps {
            sh 'run-it-1.sh'
          }
        }
        stage('IT 2 (slow)') {
          steps {
            sh 'run-it-2.sh'
          }
        }
        stage('IT 3 (quick)') {
          steps {
            sh 'run-it-3.sh'
          }
        }
      }
    }
  }
}

Edit: Using label instead of node works for declarative pipelines. Example below:

stage('IT 1 (slow)') {
  agent { label '!master' }
  steps {
    sh 'run-it-1.sh'
  }
}
noisebleed
  • 1,299
  • 2
  • 12
  • 26

1 Answers1

5

Since Declarative version 1.2, you can directly declare the kind of agent you want to use for each parallel stages : https://jenkins.io/blog/2017/09/25/declarative-1/

Not tested this specific use case, but I assume that if you don't declare any agent{} for stage "IT 3", it will be executed on the original node.

Hopefully it helps.

  • Thanks. I'm still trying to confirm it but my issue seems to come from using `node` instead of `label`. From https://stackoverflow.com/questions/42050626/jenkins-pipeline-agent-vs-node: _"Agent is for declarative pipelines and node is for scripted pipelines"_. – noisebleed Dec 07 '17 at 14:06