11pipeline {
2- agent none // assign agents per stage
3- tools {
4- maven " MAVEN" // name of Maven installation in Jenkins
5- }
6-
2+ agent none
73 stages {
8- stage(" Build on Master" ) {
9- agent { label ' built-in' } // Windows master
4+ stage(' Build on Master' ) {
5+ agent { label ' built-in' }
6+ tools { git ' Default' ; maven ' MAVEN' }
107 steps {
118 bat " mvn clean package"
12- // Archive the JAR so it can be copied to slaves
13- archiveArtifacts artifacts : " target/*.jar" , fingerprint : true
9+ stash includes : ' target/*.jar' , name : ' myAppJar'
1410 }
1511 }
1612
17- stage(" Run on Slaves" ) {
13+ stage(' Run on Slaves' ) {
1814 parallel {
19- stage(" Run on Server1" ) {
20- agent { label ' server1' } // Linux slave1
15+ stage(' Server1' ) {
16+ agent { label ' server1' }
17+ tools { git ' LinuxGit' }
2118 steps {
22- // Copy the artifact from the master
23- copyArtifacts(projectName : " ${ env.JOB_NAME} " , selector : lastSuccessful())
19+ unstash ' myAppJar'
2420 sh " java -cp target/my-app-1.0-SNAPSHOT.jar com.mycompany.app.App"
2521 }
2622 }
27- stage(" Run on Server2" ) {
28- agent { label ' server2' } // Linux slave2
23+ stage(' Server2' ) {
24+ agent { label ' server2' }
25+ tools { git ' LinuxGit' }
2926 steps {
30- // Copy the artifact from the master
31- copyArtifacts(projectName : " ${ env.JOB_NAME} " , selector : lastSuccessful())
27+ unstash ' myAppJar'
3228 sh " java -cp target/my-app-1.0-SNAPSHOT.jar com.mycompany.app.App"
3329 }
3430 }
@@ -38,7 +34,7 @@ pipeline {
3834
3935 post {
4036 success {
41- echo " Pipeline completed successfully! "
37+ archiveArtifacts artifacts : " target/*.jar "
4238 }
4339 }
4440}
0 commit comments