I have a Jenkins seed DSL job:
job("cronjob/${ACTION}_${ENVRIONMENT}_environment_CRONJOB") {
scm {
git('https://[email protected]/abc-Data/devops.git','*/develop')
}
triggers {
scm("${SCHEDULE}")
}
steps {
ansiblePlaybook("ansible/scripts/ansible-${ACTION}.yml") {
inventoryPath("/etc/ansible/hosts")
credentialsId("usercred")
extraVars {
extraVar('environment_name',"${ENVRIONMENT}",false)
}
}
}
}
ACTION, ENVIRONMENT and SCHDULE are parameters.
ACTION can have values of create
or remove
, and I have two ansible playbooks ansible-create.yml
and ansible-remove.yml
.
When I run the sseed job, I got the following error:
ERROR: (unknown source) No signature of method: javaposse.jobdsl.dsl.helpers.step.StepContext.ansiblePlaybook() is applicable for argument types: (org.codehaus.groovy.runtime.GStringImpl, script$_run_closure1$_closure4$_closure5) values: [ansible/scripts/ansible-create.yml, ...]
Finished: FAILURE
The ansiblePlaybook("ansible/scripts/ansible-${ACTION}.yml")
does not work with the variable ACTION.
If I hard code the the script name in ansiblePlaybook
, the seed job will create a new job.
The other two variables work fine in the DSL script.
What did I miss here?
Thanks!
CodePudding user response:
As @daggett suggested above, I changed the code as below:
job("cronjob/${ACTION}_${ENVRIONMENT}_environment_CRONJOB") {
scm {
git('https://[email protected]/abc-Data/devops.git','*/develop')
}
triggers {
scm("${SCHEDULE}")
}
steps {
ansiblePlaybook("ansible/scripts/ansible-${ACTION}.yml" as String) {
inventoryPath("/etc/ansible/hosts")
credentialsId("usercred")
extraVars {
extraVar('environment_name',"${ENVRIONMENT}",false)
}
}
}
}
It works as expect and create a new job with the use entered variable values. Thanks to you again @daggett!