Search code examples
jenkinsjenkins-pipelinejenkins-plugins

Jenkins trigger build every 8 commits only - How to do this?


I have a declarative pipeline I made. I'm trying to make Jenkins trigger build after every 8 commits only. I'm new to Jenkins, how do I trigger a build based on commit number?


Solution

  • Provided each commit triggers a build:

    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"
                    }
                }
            }
        }
    }