是否可以根据控制台输出重放 Jenkins 管道作业?

时间:2021-02-12 18:45:04

标签: jenkins groovy jenkins-pipeline jenkins-plugins jenkins-groovy

获取 java.lang.InterruptedException 和其他会随机终止构建的错误。我正在寻找一种可以解析日志然后在出现指定字符串时重建作业的解决方案。

Naginator 不适用于管道作业。

Groovy Postbuild 似乎没有重建功能。

PostBuild Action 只是在本地运行一个脚本/bash

1 个答案:

答案 0 :(得分:0)

我尝试创建一个场景,但有时它会是有害的,因为在失败期间同一个作业会调用自己,并且可能会导致此作业的常规失败进入无限循环。

pipeline {
    agent any;
    stages {
        stage('build') {
            steps {
                 
                script {
                    int n = env.BUILD_NUMBER
                    if( n % 2 != 0) {
                        error "I am fail because ${env.BUILD_NUMBER} % 2 = ${n % 2}"
                    }
                }
            }
        }
    }
    post {
        success {
            echo "SUCCESS ${currentBuild.result}"
        }
        failure {
            echo "FAILURE ${currentBuild.result}"
            build job: 'currentbuild', wait: false
        }
    }
}