Jenkins代码详见:
https://gitee.com/roclli/9-multipleagent.git
Jenkinsfile内容为:1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48pipeline {
    agent none
    stages {
        stage('Build') {
            agent any
            steps {
                checkout scm
                echo '---going to execute---'
                sh 'mvn -DskipTests clean package'
                stash includes: '**/target/*.jar', name: 'app'
            }
        }
        stage('Test on Linux') {
            agent {
                label 'linux'
            }
            steps {
                unstash 'app'
                sh 'mvn test -Dtest=*Test || true'
            }
            post {
                always {
                    junit '**/target/surefire-reports/TEST-**.xml'
                }
                failure {
                    echo '---on linux, there is some error---'
                }
            }
        }
        stage('Test on Windows') {
            agent {
                label 'windows'
            }
            steps {
                unstash 'app'
                bat 'mvn test -Dtest=*Test'
            }
            post {
                always {
                    junit '**/target/surefire-reports/TEST-**.xml'
                }
                failure {
                    echo '---on windows, there is some error---'
                }
            }
        }
    }
}