Jenkins JobDSL multibranchPipelineJob change script path

apr_1985 picture apr_1985 · Jan 16, 2018 · Viewed 9.2k times · Source

I am trying to create a multibranchPipelineJob in jobDSL, however the Jenkinsfile is at an alternative location to the default. I have looked through the docs https://jenkinsci.github.io/job-dsl-plugin/#path/multibranchPipelineJob and I cannot see a way to do this. Looking at the config.xml for a manually created multibranchPipelineJob the scriptPath is in the section, but I cannot find a DSL method to set this.

Can anyone offer any help on how to do this? Cheers

Answer

nerdherd picture nerdherd · Jun 9, 2018

Job DSL now exposes a way to do this:

multibranchPipelineJob('my-build') {
    factory {
        workflowBranchProjectFactory {
            scriptPath('path-to-Jenkinsfile')
        }
    }
}

Confirmed working with Job DSL 1.69, and is available since 1.67 according to the release notes.

Edit: Tested again with Job DSL 1.77 and it's still working as expected. If you want to see the documentation for this syntax you'll have to look at a Jenkins installation that has the Multibranch Pipeline plugin installed, at this path:

https://your-jenkins-url/plugin/job-dsl/api-viewer/index.html#path/multibranchPipelineJob-factory-workflowBranchProjectFactory-scriptPath