Skip to content

Instantly share code, notes, and snippets.

@jhsea3do
Created July 26, 2018 14:19
Show Gist options
  • Save jhsea3do/3e099c645d53445685428f11785290d5 to your computer and use it in GitHub Desktop.
Save jhsea3do/3e099c645d53445685428f11785290d5 to your computer and use it in GitHub Desktop.
/**
* docker pipeline sample
*/
def times = 3
def maxSeconds = 3
pipeline {
agent {
docker { image 'centos:centos7' }
}
stages {
stage('Init') {
steps {
sh 'ls -la /tmp'
sh 'hostname'
script {
// retry demo
try {
retry(times) {
sh 'hostname'
times = times - 1
if(times > 0) {
error 'pls try again'
}
}
} catch (e) {
// currentBuild.result = "FAILURE"
print e
}
// timeout demo
try {
timeout(time: maxSeconds, unit: 'SECONDS') {
sh 'sleep 5'
}
} catch (e) {
print "time over ${maxSeconds}"
}
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment