This presentation walks through a Jenkins as Code approach that aims to fully automate and describe the creation of Infrastructure, Application and Configuration as Code.
We treat our applications with a strong 'as code' approach, but often forget about the critical operational tools. This presentation shows how it is possible to create a code first approach to creating and managing a Jenkins Service.
Working code repository is available at https://bitbucket.org/stevemac/dockerfiles
3. The moving parts - AS CODE
Infrastructure (AWS / ECS)
Application (Jenkins)
Configuration (Jenkins Jobs)
CloudFormation
Docker containers
Groovy / Jenkins DSL
4. Everything as code
• Consistently repeatable process
• Enables a strong self service workflow
• Highly visible traceability of change
• Roll forward / rollback
6. Infrastructure
• Infrastructure captured as Code
• Designed for easy re-use per team
• Deployable into existing VPCs
• Common location to share learned lessons
Infrastructure / AWS
12. The Jenkins Master and its Agents
• Jenkins is an Application
• We understand the Docker application workflow
• Immutable Applications increase confidence of changes
• Based of official JenkinsCI base containers
• From jenkinsci/Jenkins
• From jenkinsci/slave
• Extended to include specific build and deployment tools
• Python / AWSCli / etc
Jenkins Application /
Docker containers
17. Configuration as Code - setup
• Start of the configuration delivered in Dockerfiles
• Configuration and ssh keys downloaded from S3 bucket
• Supplied to container as Environment variable
Configuration / Groovy
18. Configuration as Code - setup
• Runtime configuration automated through use of custom Groovy
initialisation scripts within the container
• Groovy is used to configure:
• Jenkins credentials
• ECS Cluster configuration
• Jenkins Bootstrap job
• Executed as part of Dockerfile entrypoint
Configuration / Groovy
19. Pipeline as Code - runtime
• Using the Jenkins DSL pipeline
• https://bitbucket.org/jenkinspipeline/jenkins-dsl-examples
• Using the power of Groovy code to create reusable elements
• Version controlled through Git
• Repeatable / reliable / extensible
• See https://github.com/jenkinsci/job-dsl-plugin/wiki/Tutorial---Using-the-Jenkins-Job-DSL
• Automatic documentation available within each Jenkins instance
Configuration / Jenkins DSL
Lets talk about
a Jenkinsfile
approach over a
beer
21. Pipeline as Code - example
https://bitbucket.org/jenkinspipeline/jenkins-dsl-examples
1. build_pipeline.groovy
Creation of example build jobs - CI
2. delivery_pipeline.groovy
Creation of example jobs for a candidate delivery pipeline - CD
3. views.groovy
Creation of some standard pipeline views
Configuration / Groovy /
Jenkins DSL
23. Executed within
ECS Jenkins service
Result of
infrastructure deploy
Performed by operator
Delivery workflow
Build and
Publish Docker
Containers
Launch Stack
Publish keys to
S3 bucket
Create ECS
Service
Retrieve latest
Docker image
from ECR
Launch ECS
Task
Download keys
from S3
Clone groovy
config repo
Launch Jenkins
Master Process
Groovy config
executed
Bootstrap job
generates
pipelines
24. Followup discussions
1. Migrating to a Jenkins-as-code approach
2. Jenkins DSL vs Jenkinsfiles
3. All about Jenkins State
4. Security in a stateless world
5. Advanced Jenkins DSL patterns
25. Thanks !
Steve Mactaggart
• Application Delivery Evangineer at Cevo
• @stevemac
Example working code available at:
https://bitbucket.org/stevemac/dockerfiles