Dynamic Job Names

28 views
Skip to first unread message

Jon McKenzie

unread,
Jun 15, 2017, 3:48:57 PM6/15/17
to job-dsl-plugin
I'm trying to dynamically determine job names based on running a script from the workspace (checked out via git).

Pseudocode:

job_names = execute_command('./job-names.sh')

job_names.each { job_name ->
   job(job_name) {
     ...job config...
  }
}

Is this possible? I've tried a few different things with little success. In my case, I have a "make" command that generates this list, so I'm running:

workspace = hudson.model.Executor.currentExecutor().getCurrentWorkspace().toString()
job_names = "make -C ${workspace} job-list".execute().text.split("\n")

The "job_names" variable is showing up as an empty array, so my job fails to create any jobs.

Edward Ciramella

unread,
Jul 3, 2017, 2:53:54 PM7/3/17
to job-dsl-plugin
Generally, what I've done to avoid mental lookups (jobs where the job name doesn't correspond to a repo or repo+branch, etc) is used a json slurper and consumed the names of things from a json file (vs. trying to consume some cli output).

I guess I'm left wondering what's in this script that couldn't be established before hand?

Daniel Spilker

unread,
Jul 6, 2017, 4:03:52 PM7/6/17
to job-dsl...@googlegroups.com
This should work in general. Maybe your script is failing. Also note that the Job DSL script will always run on the Jenkins master JVM. If your workspace is on a build agent (aka slave) it can not be executed from the DSL script.

You can try to run a "Execute shell" build step before the "Process Job DSLs" build steps. The shell step can run your make file and pipe the output to a temp file. You can then read temp file from the Job DSL script with readFileFromWorkspace.

https://jenkinsci.github.io/job-dsl-plugin/#path/readFileFromWorkspace

Daniel

--
You received this message because you are subscribed to the Google Groups "job-dsl-plugin" group.
To unsubscribe from this group and stop receiving emails from it, send an email to job-dsl-plugin+unsubscribe@googlegroups.com.
To post to this group, send email to job-dsl-plugin@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/job-dsl-plugin/04ab910b-aa15-4d1c-a5d0-4f2b5220b621%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages