I am an IT student and I need help with my school project.
I am trying to build a freeStyleJob that takes 2 parameters : a GitHub Repository and a Display Name to create a child job that automatically executes tests on that repository. The parent parameters should be set in stone in the childs' environment. Everything must be defined in a single job_dsl.groovy file.
The child job is at root while the parent is inside the Tools folder.
The problem I am facing is creating a "template" for that child job.
Here is my current job_dsl.groovy file :
def seedTemplate = { seedTemplate ->
freeStyleJob("seed_template") {
properties {
githubProjectUrl('https://github.com/"$GITHUB_NAME"')
}
triggers {
cron("H/1 * * * *")
githubPush()
}
wrappers {
preBuildCleanup {
deleteDirectories()
cleanupParameter('CLEANUP')
}
}
steps {
shell('ls')
shell('make')
} //steps
} //freeStyle
} //seedTemplate
freeStyleJob('/Tools/SEED') {
parameters {
stringParam("GITHUB_NAME",
null,
"GitHub repository owner/repo_name (e.g.: \"EpitechIT31000/chocolatine\")")
stringParam("DISPLAY_NAME",
null,
"Display name for the job")
}
steps {
dsl {
external("seedTemplate")
} //dsl
} //steps
} //freeStyle
I am uncertain about the dsl step although I think it might be my best chance of success. I found what I believe to be 2 useful dsl methods in the documentation: "external" and "text".
- External reads a DSL script present in the same workspace as the freeStyleJob, but how can I define a child job with the correct environment (defined in the parent parameters) without the job being created at the same time as the parent job ?
- Text generate the job based on a string, but it seems too redundant and barbarian to be helpful as I CANNOT use another file that the job_dsl.groovy
When I execute the groovy file, only the SEED freeStyleJob is generated and it runs successfully, but I get the following error when I run the child job :
Building in workspace /var/jenkins_home/workspace/Tools/SEED
ERROR: no Job DSL script(s) found at seed_template.groovy
Thank you to everyone who took the time to read my (stupid ?) question.