Jenkins仅每8次提交触发一次构建-如何做到这一点?

时间:2020-03-13 02:25:03

标签: jenkins jenkins-pipeline jenkins-plugins

我有一个声明式管道。我正在尝试仅在每8次提交后使Jenkins触发构建。 我是Jenkins的新手,如何根据提交号触发构建?

1 个答案:

答案 0 :(得分:1)

假设每次提交都会触发构建:

pipeline
    agent any
    stages {
        stage('Check 8 commits') {
            steps {
                def build_num = env.BUILD_NUMBER as int
                if (build_num % 8 != 0) {
                    error "This is not 8th commit"
                }
            }
        }
    }
}