I want to setup a Jenkins from code to
- Create one initial pipeline
- Create the Job DSL seed job and executing it to configure jobs used in the pipeline
- Configure Jenkins settings
- Locales - set locale to EN
- Access control - Lock down system
I read many tutorials and questions and found the following ideas
- Using the Jenkins CLI
- Some Job DSL interface for setting up a job as described here at the bottom
- Using JenkinsSCI interface within a Groovy file located in
init.groovy.d
- see below
For testing I use Docker and have the following sample already running.
Dockerfile
# https://github.com/jenkinsci/docker/blob/master/README.md
FROM jenkins/jenkins:lts
USER root
COPY groovy/* /usr/share/jenkins/ref/init.groovy.d/
USER jenkins
EXPOSE 8080
ENTRYPOINT ["/bin/tini", "--", "/usr/local/bin/jenkins.sh"]
groovy/jobs/test1-basic.groovy
#!/usr/bin/env groovy
import hudson.model.*
import jenkins.model.Jenkins;
import hudson.tasks.Shell;
job = Jenkins.instance.createProject(FreeStyleProject, 'test1-basic')
job.buildersList.add(new Shell('echo hello world'))
job.save()
The sample sadly lacks the
- configuration part, as I do not know how to access the locale plugin from within the groovy code
- Job DSL integration, how to read the seed job and execute it ones
I really did an intensive research and could not find much about this initial setup part. It seems many people do this manually, or the legacy way copying XML files. Could you help me out solving this and making it a "best practice documentation" for other?