Skip to content

Instantly share code, notes, and snippets.

@bhenderson
Created April 26, 2017 17:40
Show Gist options
  • Save bhenderson/c2efd6a5155bc772958babeea45890c7 to your computer and use it in GitHub Desktop.
Save bhenderson/c2efd6a5155bc772958babeea45890c7 to your computer and use it in GitHub Desktop.
/*
* Create the Dockins folder and Job DSL seed job from Groovy
* Adapted from javaposse.jobdsl.Run
*/
import hudson.model.*
import jenkins.model.*
import javaposse.jobdsl.dsl.DslScriptLoader
import javaposse.jobdsl.dsl.JobManagement
import javaposse.jobdsl.plugin.JenkinsJobManagement
import javaposse.jobdsl.dsl.GeneratedItems
import javaposse.jobdsl.dsl.GeneratedJob
import javaposse.jobdsl.dsl.GeneratedView
import javaposse.jobdsl.dsl.ScriptRequest
def env = System.getenv()
def home = env["JENKINS_REF"]
File cwd = new File(home)
URL cwdURL = cwd.toURI().toURL()
JobManagement jm = new JenkinsJobManagement(System.out, env, cwd)
String scriptName = "jobs/seed_job.dsl"
String scriptPath = new File(scriptName).absolutePath
ScriptRequest request = new ScriptRequest(scriptName, null, cwdURL, false, scriptPath)
GeneratedItems generatedItems = new DslScriptLoader(jm).runScripts([request])
for (GeneratedJob job : generatedItems.jobs) {
println("From $scriptName, Generated item: $job")
}
for (GeneratedView view : generatedItems.views) {
println("From $scriptName, Generated view: $view")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment