如何使用声明语法在 Jenkinsfile 中声明多个代理?

How to declare many agents in a Jenkinsfile with Declarative syntax?

在 Pipeline 脚本语法中,我们使用此语法向特定节点声明特定步骤:

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

但是我想用Pipeline Declarative Syntax,可以放很多代理吗?

当然可以。看看例子(来自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'
                }
            }
        }
    }
}