项目作者: vjacheslavl

项目描述 :
Jenkins automation example
高级语言: Groovy
项目地址: git://github.com/vjacheslavl/jenkins-automation.git
创建时间: 2020-08-29T14:01:03Z
项目社区:https://github.com/vjacheslavl/jenkins-automation

开源协议:Apache License 2.0

下载


Jenkins Job DSL and pipeline script gradle project

Conjoined project for jenkins pipeline management using job-dsl-plugin for job creation and jenkins-pipeline-plugin
for job logic definition using scripted pipelines.
Project supports code completion of job-dsl scripts and pipeline scripts in IntelliJ IDEA.
Just import project as gradle project using gradle wrapper.

Running all tests in this repository

./gradlew clean check

Pipelines DSL

Pipeline module contains all of scripted jenkins files

  1. .
  2. ├── resources
  3. └── pipeline.gdsl #Groovy DSL script (GDSL) file.
  4. #This can be downloaded from https://<Jenkins>/job/<Job Name>/pipeline-syntax/gdsl
  5. #enables code completion in IDE for pipeline functions
  6. ├── scripts # Jenkins pipeline script files
  7. └── build.gradle # Build file

Jenkins seeds (job-dsl)

Inspired by https://github.com/sheehan/job-dsl-gradle-example

Seeds module contains seed jobs for creating jenkins pipeline jobs as well as some helper classes like builders and utils

  1. .
  2. ├── seeds # DSL script files
  3. ├── resources # Resources for DSL scripts
  4. ├── src
  5. ├── main
  6. └── groovy # Support classes
  7. └── test
  8. └── groovy # Specs
  9. └── build.gradle # Build file

Testing of seed jobs

./gradlew :seeds:test - runs seed jobs tests.
JobScriptsSpec
will loop through all DSL files and make sure they don’t throw any exceptions when processed. All XML output files are written to build/debug-xml.
This can be useful if you want to inspect the generated XML before check-in.

Tests are using jenkins test harness

Shared libraries

https://www.jenkins.io/doc/book/pipeline/shared-libraries/

  1. .
  2. ├── src # Groovy source files
  3. ├── test # Unit tests
  4. └── vars # Reusable library functions (global vars)
  5. ├── foo.bar # Global 'foo' library
  6. └── foo.txt # Docs for global 'foo' library

Testing of shared libraries

./gradlew :check - runs shared library unit tests

Inspired by
https://github.com/macg33zr/pipelineUnit

Uses Jenkins pipelineUnit - https://github.com/jenkinsci/JenkinsPipelineUnit

Setting up local jenkins in docker

Installing Jenkins locally for development purposes

! please note that script security is disabled locally using permissive-script-security plugin
Still warnings from script security are displayed in console logs of your pipelines
In production use the scripts still has to be approved by administrators of Jenkins

  1. .
  2. ├── master
  3. ├── Dockerfile # Dockerfile for master creation
  4. └── plugins.txt # list of all plugins, that local Jenkins will install
  5. ├── jenkins.yaml # (CaSC) configuration file for jenkins. Contains all settings for new server.
  6. # https://github.com/jenkinsci/configuration-as-code-plugin
  7. ├── jenkins-docker-compose.yml # docker compose for creating jenkins master and agent
  8. ├── start-local-jenkins.sh # script for startting local jenkins
  9. └── stop-local-jenkins.sh # script for removal of local jenkins
  10. -

Starting jenkins in docker

  1. sh ./docker/start-local-jenkins.sh

creates 2 containers

  • jenkins master (with plugins preinstalled)
  • simple agent

Local jenkins url
http://localhost:8092

Creating jobs using master-seed job

Once you have local jenkins created you can proceed with creating jobs.

Use http://localhost:8092/job/master-seed job to generate all jobs from seeds