Sample package to install as an artifact into Jenkins
- Need to disable "Enable script security for Job DSL scripts" (uncheck checkbox in YOUR_JENKINS_URL/manage/configureSecurity) (otherwise you'll have to manually approve each script installed via Seed Job)
- Generate API Token for your user (User -> Security -> API Token)
- If you plan on using provided workflows, set generated API token as "JENKINS_TOKEN" secret in GitHub parameters
This repo has the following workflows:
- Create SeedJob in Jenkins - uploads seed_job.xml to Jenkins instance via jenkins-cli tool
- Trigger SeedJob in Jenkins - triggers SeedJob to install Jenkins DSL jobs from specified repo
-
For "Job DSL" plugin to correctly process your DSL scripts, script names may only contain letters, digits and underscores, but may not start with a digit (so it should be a valid Java variable name)
e.g. test-job-with-dashes.groovy will result in error during processing -
Current repo example shows how you may initialize your Jenkins folder structure:
All DSL files are processed in alphanumeric order, and if a Job is contained inside a folder, that folder should be created beforehand
That's why there is a separate_folders.groovy(starting with underscore, so it's processed first) that creates all the required folders -
All the jobs need to have full path (relative to install dir,
PROJECT_NAME- folder is passed as a variable fromtrigger_seed_jobaction)
e.g.pipelineJob("${PROJECT_NAME}/jobs/test_job_inside_folder")
It will not automatically create all the sub-folders, you need to do it as a separate DSL command