Search code examples
jenkinsautomationjobsdsl

Create Jenkins Job from DSL without seed job


From what I understand, Jenkins job creation can be automated using the Job DSL Plugin - however to evaluate the DSL, a seed job needs to be created by hand first.

I want to automate job creation without any human interaction - is there a way to transform the DSL to the corresponding .../.jenkins/jobs/job.xml without using the web front end?


Solution

  • You have 2 options to achieve this

    1. Create a Jenkins Job which creates the seed job using DSL. Job-dsl provides a capability to write configure block and if you look at the Seed job, it is nothing but pulling the DSL code from git repository. Inject the org.jenkinsci.plugins.workflow.cps.CpsScmFlowDefinition through Configure block , it should work
    2. The more elegant approach would be to use Jenkins CLI. If you are conversant with Java, you can use Jenkins Java client API and write a Small App which would create the Seed Job

      JenkinsServer jenkinsServer = new JenkinsServer(new URI(jenkinsurl), userid, password); jenkinsServer.createJob("Seed Job Name", <>, true);