@@ -3,12 +3,14 @@ pipeline {
33 tools {
44 maven " MAVEN" // name of Maven installation in Jenkins
55 }
6+
67 stages {
78 stage(" Build on Master" ) {
8- agent { label ' built-in' } // Built-in Windows master
9+ agent { label ' built-in' } // Windows master
910 steps {
1011 bat " mvn clean package"
11- stash includes : ' target/*.jar' , name : ' myAppJar'
12+ // Archive the JAR so it can be copied to slaves
13+ archiveArtifacts artifacts : " target/*.jar" , fingerprint : true
1214 }
1315 }
1416
@@ -17,14 +19,16 @@ pipeline {
1719 stage(" Run on Server1" ) {
1820 agent { label ' server1' } // Linux slave1
1921 steps {
20- unstash ' myAppJar'
22+ // Copy the artifact from the master
23+ copyArtifacts(projectName : " ${ env.JOB_NAME} " , selector : lastSuccessful())
2124 sh " java -cp target/my-app-1.0-SNAPSHOT.jar com.mycompany.app.App"
2225 }
2326 }
2427 stage(" Run on Server2" ) {
2528 agent { label ' server2' } // Linux slave2
2629 steps {
27- unstash ' myAppJar'
30+ // Copy the artifact from the master
31+ copyArtifacts(projectName : " ${ env.JOB_NAME} " , selector : lastSuccessful())
2832 sh " java -cp target/my-app-1.0-SNAPSHOT.jar com.mycompany.app.App"
2933 }
3034 }
@@ -34,7 +38,7 @@ pipeline {
3438
3539 post {
3640 success {
37- archiveArtifacts artifacts : " target/*.jar "
41+ echo " Pipeline completed successfully! "
3842 }
3943 }
4044}
0 commit comments