use groovy for Jenkins job automation

  1. 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
  2. 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

23 Replies to “use groovy for Jenkins job automation”

  1. Hello there. I discovered your site by the use of Google even as searching for a related matter, your website got here up. It appears great. I have bookmarked it in my google bookmarks to come back then. Bryna Lanny Elora

  2. Someone essentially help to make seriously articles I would state. This is the first time I frequented your web page and thus far? I amazed with the research you made to make this particular publish incredible. Great job! Tomi Giordano Kirkwood

  3. Wonderful beat ! I would like to apprentice while you amend your site, how can i subscribe for a blog site? The account helped me a acceptable deal. I had been tiny bit acquainted of this your broadcast provided bright clear concept Rose Keary Crary

  4. Greetings! Very useful advice in this particular article! It is the little changes which will make the most significant changes. Many thanks for sharing! Gert Stearne Sladen

  5. Wow, amazing blog format! How lengthy have you been running a blog for? you make running a blog look easy. The entire glance of your website is excellent, as neatly as the content! Delphinia Nevil Adna

  6. You actually make it seem so easy with your presentation but I find this matter to be really something which I think I would never understand. It seems too complicated and very broad for me. I am looking forward for your next post, I will try to get the hang of it! Laney Grantley Theran

  7. Hello there! This article could not be written much better! Looking at this post reminds me of my previous roommate! He constantly kept talking about this. I most certainly will send this article to him. Fairly certain he will have a great read. Thanks for sharing! Berti Kerwinn Liman

Leave a Reply

Your email address will not be published. Required fields are marked *