https://e.printstacktrace.blog/how-to-time-out-jenkins-pipeline-stage-and-keep-the-pipeline-running/
pipeline {
agent any
options{
timestamps()
}
stages {
stage("A") {
options {
timeout(time: env.timeout, unit: "SECONDS")
//MINUTES
}
steps {
script {
Exception caughtException = null
catchError(buildResult: ‘SUCCESS‘, stageResult: ‘ABORTED‘) {
try {
echo "Started stage A"
sleep(time: 5, unit: "SECONDS")
} catch (org.jenkinsci.plugins.workflow.steps.FlowInterruptedException e) {
error "Caught ${e.toString()}"
} catch (Throwable e) {
caughtException = e
}
}
if (caughtException) {
error caughtException.message
}
}
}
}
stage("B") {
steps {
echo "Started stage B"
}
}
}
}
pipeline {
agent any
stages {
stage(‘1‘) {
steps {
// build job:‘test‘
echo ‘in 1‘
}
}
stage(‘2‘) {
steps {
catchError(buildResult: ‘SUCCESS‘, stageResult: ‘FAILURE‘) {
build job:‘test‘
}
}
}
stage(‘3‘) {
steps {
echo ‘in 3‘
}
}
}
}
pipeline {
agent any
stages {
stage(‘1‘) {
steps {
script {
try{
build job: ‘test‘
}
catch (err){
echo "test failed"
}
}
}
}
stage(‘2‘) {
steps {
script {
try{
build job: ‘test‘
}
catch (err){
echo "test failed"
}
}
}
}
stage(‘3‘) {
steps {
script {
try{
build job: ‘test‘
}
catch (err){
echo "test failed"
}
}
}
}
}
}
原文:https://www.cnblogs.com/amize/p/14735995.html