Skip to content

Commit 856a4e2

Browse files
authored
Update Jenkinsfile
1 parent c2ef825 commit 856a4e2

File tree

1 file changed

+33
-16
lines changed

1 file changed

+33
-16
lines changed

Jenkinsfile

Lines changed: 33 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,40 @@
11
pipeline {
2-
agent none
2+
agent none // No global agent, define per stage
33

44
stages {
5-
stage('Build') {
6-
agent { label 'built-in' }
7-
tools { maven 'MAVEN' }
8-
steps {
9-
bat 'mvn clean install -DskipTests'
10-
stash includes: 'target/my-app-1.0-SNAPSHOT.jar', name: 'app-jar'
11-
}
12-
}
135

14-
stage('Run on Slave') {
15-
agent { label 'docker' }
16-
steps {
17-
unstash 'app-jar'
18-
sh 'java -jar my-app-1.0-SNAPSHOT.jar'
19-
}
20-
}
6+
stage('Build') {
7+
agent { label 'built-in' } // Master node (Windows)
8+
tools { maven 'MAVEN' }
9+
steps {
10+
// Clean build, skip tests
11+
bat 'mvn clean install -DskipTests'
12+
13+
// Stash the JAR for slave
14+
stash includes: 'target/my-app-1.0-SNAPSHOT.jar', name: 'app-jar', useDefaultExcludes: false
15+
}
16+
}
17+
18+
stage('Test') {
19+
agent { label 'built-in' } // Master node (Windows)
20+
tools { maven 'MAVEN' }
21+
steps {
22+
bat 'mvn test'
23+
}
24+
}
25+
26+
stage('Run on Slave') {
27+
agent { label 'docker' } // Slave node label
28+
steps {
29+
// Clean workspace on slave before unstashing
30+
sh 'rm -rf *'
31+
32+
// Retrieve the JAR
33+
unstash 'app-jar'
2134

35+
// Run the JAR
36+
sh 'java -jar target/my-app-1.0-SNAPSHOT.jar'
37+
}
38+
}
2239
}
2340
}

0 commit comments

Comments
 (0)