Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save ctran/01eac093ac12def1b3ffbcedf07bf30a to your computer and use it in GitHub Desktop.
Save ctran/01eac093ac12def1b3ffbcedf07bf30a to your computer and use it in GitHub Desktop.

Revisions

  1. @djfdyuruiry djfdyuruiry renamed this gist Feb 18, 2018. 1 changed file with 0 additions and 0 deletions.
  2. @djfdyuruiry djfdyuruiry renamed this gist Feb 18, 2018. 1 changed file with 0 additions and 0 deletions.
  3. @djfdyuruiry djfdyuruiry created this gist Feb 18, 2018.
    46 changes: 46 additions & 0 deletions multiBrachWithCustomStrategyAndScriptPath.groovy
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,46 @@
    UUID uuid = UUID.randomUUID()

    multibranchPipelineJob("my_awesome_job") {
    displayName "my awesome job"
    description "multi-branch pipeline job thingy"
    configure {
    it / sources / 'data' / 'jenkins.branch.BranchSource' << {
    source(class: 'jenkins.plugins.git.GitSCMSource') {
    id(uuid)
    remote("git@gitlab:root/repo.git")
    credentialsId("ssh_key")
    includes('*')
    excludes('')
    ignoreOnPushNotifications('false')
    traits {
    'jenkins.plugins.git.traits.BranchDiscoveryTrait'()
    }
    }
    // default strategy when sourcing from a branch
    strategy(class: "jenkins.branch.NamedExceptionsBranchPropertyStrategy") {
    defaultProperties(class: "java.util.Arrays\$ArrayList") {
    a(class: "jenkins.branch.BranchProperty-array") {
    // don't trigger builds
    "jenkins.branch.NoTriggerBranchProperty"()
    }
    }
    // exceptions to the default strategy
    namedExceptions(class: "java.util.Arrays\$ArrayList") {
    a(class: "jenkins.branch.NamedExceptionsBranchPropertyStrategy\$Named-array") {
    "jenkins.branch.NamedExceptionsBranchPropertyStrategy_-Named"() {
    // for the brach named `master` trigger builds
    // (this is default behaviour if no branch properties are specified)
    props(class: "empty-list")
    name("master")
    }
    }
    }
    }
    }
    // customise the branch project factory
    it / factory(class: "org.jenkinsci.plugins.workflow.multibranch.WorkflowBranchProjectFactory") << {
    // pipeline jobs will have their script path set to `pipelines/customPipeline.groovy`
    scriptPath("pipelines/customPipeline.groovy")
    }
    }
    }