Search code examples
jenkinsjenkins-pipelinejenkins-job-dslmultibranch-pipeline

Jenkins DSL multibranch pipeline github push trigger


I am using the jenkins dsl plugin multibranchpipeline job(https://jenkinsci.github.io/job-dsl-plugin/#path/multibranchPipelineJob) to create a multi branch pipeline. I have created jenkinsfile which handles the build jobs for each branches. I couldnt figure out how the github push trigger can be enabled through pipeline as code. All the examples I could find are using the jenkins web UI or the pollscm option. Can someone please help on how this can be enabled through code.


Solution

  • Project was hosted in github.In jenkins dsl multibranchpipeline, i was using the git branchsource at first. Then push events were not triggering builds. After i started using github branchsource, push events were automatically generating builds.

    ie.

    multibranchPipelineJob('example') {
    branchSources {
        git {
            id('12121212') // IMPORTANT: use a constant and unique identifier
            remote('https://github.com/jenkinsci/job-dsl-plugin.git')
            credentialsId('github-ci')
            includes('JENKINS-*')
        }
    }
    }
    

    Was changed to

    multibranchPipelineJob('example') {
    branchSources {
        github {
            id('23232323') // IMPORTANT: use a constant and unique identifier
            scanCredentialsId('github-ci')
            repoOwner('OwnerName')
            repository('job-dsl-plugin')
        }
    }
    }