Search code examples
githubjenkinsjenkins-job-dslmultibranch-pipeline

Jenkins Multibranch-Pipeline JobDSL can't specify github url


I'm creating a Multibranch Pipeline job with JobDSL , and I want to specify my github url , but it's not working.

The job which I created it display "https://github.com/jackson/multibranch-Pipeline.git" ,

not https://mycompanygithub.com/jackson/multibranch-Pipeline.git

Any idea how theses other parameters can be added in ?

or other solution

multibranchPipelineJob('Jenkins/Multibranch-Pipeline/GitHub_Basic') {
    branchSources {
        branchSource {
            source {
                github {
                    repositoryUrl('https://mycompanygithub.com')
                    credentialsId('mycredentialsid')
                    repoOwner('jackson')
                    repository('multibranch-Pipeline.git')
                    configuredByUrl(true)
                    }
                }
            }
        }
    }


Solution

  • Actually your configuration is correct, your are just missing one parameter: apiUri

    // The server to connect to.
    apiUri(String value)

    Without it, it takes the default github.com as the base domain for the repository regardless of what is configured in the repositoryUrl parameter.
    Try the following:

    multibranchPipelineJob('Jenkins/Multibranch-Pipeline/GitHub_Basic') {
       branchSources {
           branchSource {
               source {
                   github {
                       apiUri('https://mycompanygithub.com/api/v3')
                       repositoryUrl('https://mycompanygithub.com')
                       credentialsId('mycredentialsid')
                       repoOwner('jackson')
                       repository('multibranch-Pipeline.git')
                       configuredByUrl(true)
                   }
               }
           }
       }
    }
    

    By the way you can see the full documentation of the Job DSL of this plugin at the following URL on your own Jenkins server: YOUR_JENKINS_URL/plugin/job-dsl/api-viewer/index.html#method/javaposse.jobdsl.dsl.DslFactory.multibranchPipelineJob