Created
July 26, 2018 14:19
-
-
Save jhsea3do/3e099c645d53445685428f11785290d5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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