3

In the Pipeline scripted syntax we use this syntax to declare specific steps to specific nodes:

steps{
    node('node1'){
        // sh
    }
    node('node2'){
        // sh
    }
}

But I want to use the Pipeline Declarative Syntax, can I put many agents?

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
sirineBEJI
  • 1,170
  • 2
  • 14
  • 25

1 Answers1

4

Sure you can. Just take a look at example (from docs):

pipeline {
    agent none
    stages {
        stage('Build') {
            agent any
            steps {
                checkout scm
                sh 'make'
                stash includes: '**/target/*.jar', name: 'app' 
            }
        }
        stage('Test on Linux') {
            agent { 
                label 'linux'
            }
            steps {
                unstash 'app' 
                sh 'make check'
            }
            post {
                always {
                    junit '**/target/*.xml'
                }
            }
        }
        stage('Test on Windows') {
            agent {
                label 'windows'
            }
            steps {
                unstash 'app'
                bat 'make check' 
            }
            post {
                always {
                    junit '**/target/*.xml'
                }
            }
        }
    }
}
mkobit
  • 43,979
  • 12
  • 156
  • 150
Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
  • Thank you, is agent in declarative syntax equivalent to node in scripted syntax? I saw in the documentation that node just adds additional options (such as customWorkspace) – sirineBEJI Mar 27 '18 at 08:59
  • Yes. But you need to define your build steps in `steps`, while in scripted syntax they are just defined inside of `node`. You can toggle declarative/scripted syntax in examples in docs, just take a look at the differences. – Vadim Kotov Mar 27 '18 at 09:03
  • Also, [agent vs node](https://stackoverflow.com/questions/42050626/jenkins-pipeline-agent-vs-node) – Vadim Kotov Mar 27 '18 at 09:15