github organization folder job from dsl

558 views
Skip to first unread message

Ryan Thornton

unread,
Mar 23, 2018, 2:09:41 PM3/23/18
to job-dsl-plugin

Hello,

I'm struggling to understand how to setup a GitHub Organization project using the Job DSL. 

I don't understand how to use the `projectFactories` extension point of the `organizationFolder(){...}`  command.

The best I can come up with is this:


organizationFolder('org') {
    configure
{
        it
/ navigators / "org.jenkinsci.plugins.github__branch__source.GitHubSCMNavigator" << {
            repoOwner
("org")
            apiUri
("apiurl")
            credentialsId
("credentials")
       
}
   
}
    configure
{
        it
/ projectFactories / "org.jenkinsci.plugins.workflow.multibranch.WorkflowMultiBranchProjectFactory" << {
            scriptPath
("Jenkinsfile")
       
}
   
}
}


Which works, but  seems overly hacky.

JENKINS-45528 seems very relevant, and has been merged, but the proposed syntax from the OP doesn't work. And I don't understand what syntax to use to take advantage of it.

Any thoughts? How do I use `projectFactories`?

Thanks,
Ryan

Ryan Thornton

unread,
May 16, 2018, 10:53:05 AM5/16/18
to job-dsl-plugin
Ok, I think I have it figured out.

As best I can tell, the `projectFactories` extension point cannot be executed used when running through the  Jenkins Job DSL Playground or when executing a DSL script locally. This was tripping me up. 

The extension point does exist. But the function is considered "Dynamic" as described by the Dynamic DSL wiki. You can learn more about these functions by going to your https://your-jenkins-server/plugin/job-dsl/api-viewer/index.html, where you can further drop down into the method and see what properties it supports.

In my case, on my Jenkins server with the GitHub Organization plugin installed, in the API Viewer I now see the following:

// Sets the project factories for this folder.
projectFactories {
}


But note, the above syntax will not work when running from the Command Line or through the Playground:

The dynamic DSL is only supported when running in Jenkins, e.g. it is not available when running from the command line or in the Playground. Use The Configure Block to generate custom config elements when not running in Jenkins.

This wasn't immediately apparent to me, but now it makes sense.
Reply all
Reply to author
Forward
0 new messages