Created
April 26, 2017 17:40
-
-
Save bhenderson/c2efd6a5155bc772958babeea45890c7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* 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