I'm trying to create a DSL job that will create jobs from a list of maps iterating throughout them like the following:
def git_branch = "origin/awesomebranch"
def credential_id = "awesomerepocreds"
def jobs = [
[
title: "AwesomePipeline",
description: "This pipeline is awesome.",
directory: "awesomepath",
repo: "ssh://git@bitbucket.XXX.XX.XX:XXXX/repo/repo.git"
]
]
jobs.each { i ->
pipelineJob(i.title) {
description("${i.description}\n\n__branch__: ${git_branch}")
parameters {
stringParam('branch', defaultValue='origin/develop', description='Branch to build')
}
definition {
cpsScm {
scm {
git {
branch('$branch')
remote {
url(i.repo)
credentials(credential_id)
}
}
scriptPath("jenkins/${i.directory}/Jenkinsfile")
}
}
}
}
}
For jobs without parameters this works great but I don't know how to pass a list into the map of a job that will be used by the parameters block, something like
....
def jobs = [
[
title: "AwesomePipeline",
description: "This pipeline is awesome.",
directory: "awesomepath",
repo: "ssh://git@bitbucket.XXX.XX.XX:XXXX/repo/repo.git",
params: [
stringParam('branch', defaultValue='origin/develop', description='Branch to build'),
stringParam('sawesomeparam', defaultValue='awesomevalue', description='awesomething')
]
]
]
...
That might be used someway as some sort of each but not sure how to formulate this properly.
....
jobs.each { i ->
pipelineJob(i.title) {
description("${i.description}\n\n__branch__: ${git_branch}")
parameters {
i.params.each { p ->
p
}
}
....
Thanks in advance