- we can find latest Jenkins version from https://www.jenkins.io/download/, if we select Docker, to use the latest LTS:
docker pull jenkins/jenkins:lts
- git clone https://github.com/zhuby1973/jenkins-docker-groovy.git
root@ubunu2004:~/jenkins-docker-groovy# ls build.sh config.xml create-seed-job.groovy Dockerfile plugins.groovy plugins.txt README.md security.groovy seeddsl.groovy root@ubunu2004:~/jenkins-docker-groovy# cat Dockerfile FROM jenkins/jenkins:lts ENV JAVA_OPTS="-Djenkins.install.runSetupWizard=false" COPY security.groovy /usr/share/jenkins/ref/init.groovy.d/security.groovy COPY seeddsl.groovy /usr/share/jenkins/seeddsl.groovy COPY config.xml /usr/share/jenkins/seed-job-config.xml COPY create-seed-job.groovy /usr/share/jenkins/ref/init.groovy.d/create-seed-job.groovy COPY plugins.txt /usr/share/jenkins/ref/plugins.txt RUN /usr/local/bin/install-plugins.sh < /usr/share/jenkins/ref/plugins.txt root@ubunu2004:~/jenkins-docker-groovy# cat build.sh #!/bin/bash docker rm -f `docker ps -a -q` docker build -t local/jenkins . && docker run --name jenkins -d -p 80:8080 -p 50000:50000 local/jenkins && docker logs -f `docker ps -a -q`
3. sh build.sh you will get Jenkins Docker image build and running on port 80, you can login with admin/admin (which we created from security.groovy
4. run “seed” job, you will find another job “DSL-Tutorial-1-Test” created successfully!
5. we installed two important plugins: Seed Jenkins plug-in and Authorize Project for this automation. you can manually approve groovy script in “In-process Script Approval”, or you can install Authorize Project, then update “Configure Global Security” => “Access Control for Builds” as below:
6. reference link:
https://plugins.jenkins.io/job-dsl/
https://github.com/jenkinsci/seed-plugin/wiki/Generation
https://github.com/jenkinsci/job-dsl-plugin/wiki/Tutorial—Using-the-Jenkins-Job-DSL