Skip to content

Commit b67a0e1

Browse files
authored
Update code snippets with retry step (#1556)
1 parent 8567809 commit b67a0e1

File tree

3 files changed

+18
-12
lines changed

3 files changed

+18
-12
lines changed

src/main/resources/org/csanchez/jenkins/plugins/kubernetes/pipeline/samples/declarative.groovy

+1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ spec:
2727
// sh 'hostname'
2828
// }
2929
defaultContainer 'shell'
30+
retries 2
3031
}
3132
}
3233
stages {

src/main/resources/org/csanchez/jenkins/plugins/kubernetes/pipeline/samples/maven.groovy

+12-9
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,17 @@ kind: Pod
77
spec:
88
containers:
99
- name: maven
10-
image: maven:3.6.3-jdk-8
10+
# In a real Jenkinsfile, it is recommended to pin to a specific version and use Dependabot or Renovate to bump it.
11+
image: maven:latest
1112
command:
1213
- sleep
1314
args:
1415
- infinity
1516
''') {
16-
node(POD_LABEL) {
17-
// or, for example: git 'https://github.com/jglick/simple-maven-project-with-tests'
18-
writeFile file: 'pom.xml', text: '''
17+
retry(count: 2, conditions: [kubernetesAgent(), nonresumable()]) {
18+
node(POD_LABEL) {
19+
// or, for example: git 'https://github.com/jglick/simple-maven-project-with-tests'
20+
writeFile file: 'pom.xml', text: '''
1921
<project xmlns="http://maven.apache.org/POM/4.0.0">
2022
<modelVersion>4.0.0</modelVersion>
2123
<groupId>sample</groupId>
@@ -45,17 +47,18 @@ spec:
4547
</properties>
4648
</project>
4749
'''
48-
writeFile file: 'src/test/java/sample/SomeTest.java', text: '''
50+
writeFile file: 'src/test/java/sample/SomeTest.java', text: '''
4951
package sample;
5052
public class SomeTest {
5153
@org.junit.Test
5254
public void checks() {}
5355
}
5456
'''
55-
container('maven') {
56-
sh 'mvn -B -ntp -Dmaven.test.failure.ignore verify'
57+
container('maven') {
58+
sh 'mvn -B -ntp -Dmaven.test.failure.ignore verify'
59+
}
60+
junit '**/target/surefire-reports/TEST-*.xml'
61+
archiveArtifacts '**/target/*.jar'
5762
}
58-
junit '**/target/surefire-reports/TEST-*.xml'
59-
archiveArtifacts '**/target/*.jar'
6063
}
6164
}

src/main/resources/org/csanchez/jenkins/plugins/kubernetes/pipeline/samples/windows.groovy

+5-3
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,11 @@ spec:
1919
nodeSelector:
2020
kubernetes.io/os: windows
2121
''') {
22-
node(POD_LABEL) {
23-
container('shell') {
24-
powershell 'Get-ChildItem Env: | Sort Name'
22+
retry(count: 2, conditions: [kubernetesAgent(), nonresumable()]) {
23+
node(POD_LABEL) {
24+
container('shell') {
25+
powershell 'Get-ChildItem Env: | Sort Name'
26+
}
2527
}
2628
}
2729
}

0 commit comments

Comments
 (0)