Study Notes
Study Notes
5
Continuous Delivery/Continuous Integration Concepts .................................................... 5
Define continuous integration, continuous delivery, continuous deployment ..... 5
Difference between CI and CD .................................................................................................. 5
Stages of CI and CD ....................................................................................................................... 5
Continuous delivery versus continuous deployment ...................................................... 5
Jobs .......................................................................................................................................................... 6
What are jobs in Jenkins? ........................................................................................................... 6
Types of jobs.................................................................................................................................... 6
Scope of jobs .................................................................................................................................... 6
Builds ...................................................................................................................................................... 6
What are builds in Jenkins? ....................................................................................................... 6
What are build steps, triggers, artifacts, and repositories? .......................................... 6
Build tools configuration ............................................................................................................ 6
Source Code Management .............................................................................................................. 6
What are source code management systems and how are they used? .................... 6
Cloud-based SCMs ......................................................................................................................... 6
Jenkins changelogs ........................................................................................................................ 6
Incremental updates v clean check out................................................................................. 7
Checking in code ............................................................................................................................ 7
Infrastructure-as-Code ................................................................................................................ 7
Branch and Merge Strategies .................................................................................................... 7
Testing .................................................................................................................................................... 7
Benefits of testing with Jenkins ............................................................................................... 7
Define unit test, smoke test, acceptance test, automated verification/functional
tests..................................................................................................................................................... 7
Notifications ......................................................................................................................................... 7
Types of notifications in Jenkins ............................................................................................. 7
Importance of notifications ....................................................................................................... 7
Distributed Builds .............................................................................................................................. 7
What are distributed builds? .................................................................................................... 7
Functions of masters and slaves .............................................................................................. 7
Plugins .................................................................................................................................................... 8
What are plugins? .......................................................................................................................... 8
What is the plugin manager? .................................................................................................... 8
Jenkins Rest API .................................................................................................................................. 8
How to interact with it ................................................................................................................ 8
Why use it? ....................................................................................................................................... 8
Security .................................................................................................................................................. 8
Authentication versus authorization ..................................................................................... 8
Matrix security ............................................................................................................................... 8
Fingerprints.......................................................................................................................................... 8
What are fingerprints? ................................................................................................................ 8
How do fingerprints work? ....................................................................................................... 8
Artifacts .................................................................................................................................................. 9
How to use artifacts in Jenkins ................................................................................................. 9
Configuration Management (Tools such as Chef, Puppet, etc.) ........................................ 9
Elements of software configuration management ........................................................... 9
Change management policies ................................................................................................... 9
Importance of software configuration management....................................................... 9
Using 3rd party tools .......................................................................................................................... 9
How to use 3rd party tools with Jenkins ............................................................................... 9
Chapter 2 – Jenkins Usage ................................................................................................................ 10
Jobs ....................................................................................................................................................... 10
Organizing jobs in Jenkins ...................................................................................................... 10
Parameterized jobs .................................................................................................................... 10
Usage of Freestyle/Pipeline/Matrix/Maven/Literate ................................................. 10
Builds ................................................................................................................................................... 10
Setting up build steps and triggers ...................................................................................... 10
Configuring build tools ............................................................................................................. 10
Running scripts as part of build steps ................................................................................ 10
Source Code Management ........................................................................................................... 11
Polling source code management ........................................................................................ 11
Creating hooks ............................................................................................................................. 11
Including version control tags and version information ............................................ 11
Testing ................................................................................................................................................. 11
Testing for code coverage ....................................................................................................... 11
Test reports in Jenkins ............................................................................................................. 11
Displaying test results .............................................................................................................. 11
Integrating with test automation tools .............................................................................. 12
Breaking builds ........................................................................................................................... 12
Notifications ...................................................................................................................................... 12
Setup and usage .......................................................................................................................... 12
Email notifications, instant messaging, build radiators .............................................. 12
Alarming on notifications ........................................................................................................ 12
Distributed Builds ........................................................................................................................... 12
Setting up and running builds in parallel .......................................................................... 12
Setting up and using SSH slaves, JNLP slaves, cloud slaves ....................................... 12
Monitoring nodes ....................................................................................................................... 12
Plugins ................................................................................................................................................. 12
Setting up and using Plugin Manager ................................................................................. 12
Finding and configuring required plugins ........................................................................ 13
CI/CD .................................................................................................................................................... 13
Using Pipeline (formerly known as Workflow) .............................................................. 13
Integrating automated deployment .................................................................................... 13
Release management process ............................................................................................... 13
Pipeline stage behavior ............................................................................................................ 13
Jenkins Rest API ............................................................................................................................... 13
Using REST API to trigger jobs remotely, access job status, create/delete jobs 13
Security ............................................................................................................................................... 14
Setting up and using security realms.................................................................................. 14
User database, project security, Matrix security ............................................................ 14
Setting up and using auditing ................................................................................................ 14
Setting up and using credentials .......................................................................................... 14
Fingerprints....................................................................................................................................... 15
Fingerprinting jobs shared or copied between jobs ..................................................... 15
Artifacts ............................................................................................................................................... 15
Copying artifacts ......................................................................................................................... 15
Using artifacts in Jenkins ......................................................................................................... 15
Artifact retention policy........................................................................................................... 15
Alerts .................................................................................................................................................... 15
Making basic updates to jobs and build scripts .............................................................. 15
Troubleshooting specific problems from build and test failure alerts .................. 15
Chapter 3 – Building Continuous Delivery Pipelines ............................................................. 16
Pipeline Concepts ............................................................................................................................ 16
Value stream mapping for CD pipelines ............................................................................ 16
Why create a pipeline? ............................................................................................................. 16
Gates within a CD pipeline ...................................................................................................... 16
How to protect centralized pipelines when multiple groups use same tools ..... 16
Definition of binary reuse, automated deployment, multiple environments ..... 16
Elements of your ideal CI/CD pipeline – tools ................................................................ 16
Key concepts in building scripts (including security/password, environment
information, etc.) ........................................................................................................................ 16
Upstreams and downstreams..................................................................................................... 16
Triggering jobs from other jobs ............................................................................................ 16
Setting up the Parameterized Trigger plugin .................................................................. 17
Upstream/downstream jobs .................................................................................................. 17
Triggering........................................................................................................................................... 17
Triggering Jenkins on code changes ................................................................................... 17
Difference between push and pull ....................................................................................... 17
When to use push vs pull ......................................................................................................... 17
Pipeline (formerly known as Workflow) ............................................................................... 17
Benefits of Pipeline vs linked jobs ....................................................................................... 17
Functionalities offered by Pipeline...................................................................................... 17
How to use Pipeline ................................................................................................................... 18
Pipeline stage concurrency..................................................................................................... 18
Visualization...................................................................................................................................... 18
Options to visualize jobs’ relationships ............................................................................. 18
When to use various options for visualizing jobs’ relationships ............................. 18
Information offered by a build pipeline view .................................................................. 18
How to set up build pipeline visualization ....................................................................... 18
Folders ................................................................................................................................................. 18
How to control access to items in Jenkins with folders ............................................... 18
Referencing jobs in folders ..................................................................................................... 18
Parameters ........................................................................................................................................ 18
Setting up test automation in Jenkins against an uploaded executable ................ 18
Passing parameters between jobs ....................................................................................... 19
Identifying parameters and how to use them: file parameter, string parameter
........................................................................................................................................................... 19
Jenkins CLI parameters ............................................................................................................ 19
Promotions ........................................................................................................................................ 19
Promotion of a job...................................................................................................................... 19
Why promote jobs? .................................................................................................................... 19
How to use the Promoted Builds plugin ............................................................................ 19
CD Metrics .......................................................................................................................................... 19
KPIs/metrics for CI/CD ............................................................................................................ 19
Determining how many builds failed, succeeded .......................................................... 19
Determining how long a build takes ................................................................................... 20
Determining how often code is checked-in ...................................................................... 20
How to use metrics/KPIs......................................................................................................... 20
Notifications ...................................................................................................................................... 20
How to radiate information on CD pipelines to teams ................................................ 20
Chapter 4 – CD as Code Best Practices......................................................................................... 21
Distributed builds architecture ................................................................................................. 21
Fungible (replaceable) slaves..................................................................................................... 21
Master-slave connectors and protocol ................................................................................... 21
Tool installations on slaves ......................................................................................................... 21
Cloud slaves ....................................................................................................................................... 21
Containerization .............................................................................................................................. 21
Traceability........................................................................................................................................ 21
High availability ............................................................................................................................... 21
Automatic repository builds ....................................................................................................... 21
Chapter 5 – Cloudbees Jenkins Platform..................................................................................... 22
Reference architecture .................................................................................................................. 22
Role-based Access Control (RBAC) .......................................................................................... 22
Folders Plus ....................................................................................................................................... 22
Templates ........................................................................................................................................... 23
Setting up High Availability (HA) .............................................................................................. 23
CloudBees Jenkins Operations Center (CJOC) ...................................................................... 23
Shared clouds ............................................................................................................................... 23
Cloud configurations ................................................................................................................. 24
Shared slaves................................................................................................................................ 24
Analytics ............................................................................................................................................. 24
Cluster Operations .......................................................................................................................... 24
Pipeline Checkpoints (formerly known as Pipeline Checkpoints)............................... 25
Custom Update Center .................................................................................................................. 25
Multi-branch ..................................................................................................................................... 26
Docker plugins ................................................................................................................................. 26
Chapter 1 – Key CI/CD/Jenkins Concepts
Stages of CI and CD
Start with the commit stage which compiles and runs unit tests.
Then run longer tests/quality tools/ Ex: acceptance tests (given/when/then)
Finally, deploy
Types of jobs
Freestyle project
Maven project
Pipeline
Multi configuration
Multi branch
Long running
Scope of jobs
Not sure what this means – Maybe that there is a long running job type?
Builds
Cloud-based SCMs
Jenkins changelogs
Checking in code
Should be at least daily with CI
Infrastructure-as-Code
Storing everything needed to build your environment
Testing
Benefits of testing with Jenkins
Fast feedback!
Define unit test, smoke test, acceptance test, automated verification/functional tests
Unit test – test one class, often involves test doubles
Integration/functional test – test components together
Smoke test – sanity check to reject a release. Looking for major errors.
Acceptance test – user level test for feature
Notifications
Types of notifications in Jenkins
Failure, second failure, success, etc
Active/push – radiators/SMS vs passive/pull – rss/dashboard
RSS - /rssAll, /rssFailed and rssLatest
Radiator view plugin uses the entire screen
Extreme feedback – physical/audio devices
Importance of notifications
Fixing a build is high priority so need to know it is broken
Communicating the status to all parties
Distributed Builds
What are distributed builds?
Running builds on a different machine than master
Plugins
What are plugins?
Add functionality to core Jenkins
Security
Authentication versus authorization
Authentication – identify a user
Authorization – what user can do
Matrix security
Maps roles to permissions
Major categories: overall, slave, job, run, view and SCM
Definition of auditing, credentials, and other key security concepts
Auditing – logging user operations and changes
Credentials – username/password or the like for access
Fingerprints
What are fingerprints?
MD5 checksum of files
UI says for jar files, but works for any type of file
Parameterized jobs
Check “This build is parameterized” and enter parameters/default values
Run directly with “Build with Parameters” or call from upstream job with
“trigger parameterized build” post build action and passing parameters
Usage of Freestyle/Pipeline/Matrix/Maven/Literate
Freestyle – most flexible job
Pipeline – enter code in DSL. There is a snippet generator which generates
the Groovy for common operations and lists the available environment
variables.
Matrix (multi-config) – Specify a configuration matrix with one or more
dimensions. Runs all combinations when build.
o Axis: slave, label (for slave) or user defined (string)
o Combination filter: if don’t want cross product of all axis to run
o Can execution “touchstone” builds first to specify which job(s) should
run first and if this should skip the others
Maven - less options than Freestyle since can assume based on Maven
conventions
Literate – brand new plugin (Dec 2015) – allows specifying build commands
in README.md file in source control. A literate job is a type of multi-branch
job. (searches for new branches and creates jobs in folder automatically)
Builds
Setting up build steps and triggers
Common build steps include Maven/Ant, execute shell, start/stop Docker
container
Common triggers include time/periodic, SCM polling, upon completion of
another job
Creating hooks
Hook script in repository triggers job
Ex: Github plugin provides hook
Testing
Testing for code coverage
In build, must create XML file with data
Post Build Action to publish
For Java: Cobertura and JaCoCo
In Cobertura, can set thresholds for weather icons:
o Sunny - % higher than threshold
o Stormy - % lower than threshold
o Unstable - % lower than threshold
In Jacoco, can set thresholds for sunny and stormy
Breaking builds
JUnit allows choosing whether to fail builds on test failures - default is
“unstable” not failure
Notifications
Setup and usage
Setup in post build action section
Alarming on notifications
Extreme notifications can have a video or audio cue in the real world
Distributed Builds
Setting up and running builds in parallel
Builds run on different executors
Multi-configuration jobs run the pieces in parallel
Monitoring nodes
Monitoring page uses JMelody
Memory/CPU/etc stats
Can see heap dump/GC/etc
Plugins
Setting up and using Plugin Manager
Can provide a HTTP proxy if needed
Can specify alternate update center URL for JSON
Listed installed plugins
Can install/upgrade/uninstall plugin
Can unpin plugin so doesn’t use specific version of plugin
CI/CD
Using Pipeline (formerly known as Workflow)
Use DSL to specify jobs to be built
Example: node { stage ‘x’ echo ‘1’ stage ‘y’ echo ‘2’ }
Sample commands:
o build 'jeanne-test'
o svn - checkout
o retry – retry body up to X times
o timeout – limit time spent in block
o stash/unstash
o load – include a Groovy script
o parallel – specify two branches to run in parallel and whether to
failFast
When run build, see table with column and duration for each stage. Row is
build #. Cell color coded for pass/fail. Can see log for each stage.
Security
Setting up and using security realms
Choices include Servlet Container, Google SSO, OpenId, Jenkins user database,
LDAP, UNIX group/user database, JCOC SSO
Artifacts
Copying artifacts
Build step to copy artifacts from another build
Can choose which ones want to include/exclude by pattern
Alerts
Making basic updates to jobs and build scripts
Not sure what they mean here
How to protect centralized pipelines when multiple groups use same tools
Not sure what this means. Approvals? Security?
Upstream/downstream jobs
If A depends on B, B is the upstream job
Triggering
Triggering Jenkins on code changes
For a commit build
Visualization
Options to visualize jobs’ relationships
Build Pipeline view – shows upstream/downstream dependencies for one
job
A pipeline automatically creates a stage view – can click to see “Full Stage
View”
Delivery pipeline view – not on exam? – shows more details about stages
Folders
How to control access to items in Jenkins with folders
Role Based Access Control can control folder
Can control level as current/child/grandchild
Parameters
Setting up test automation in Jenkins against an uploaded executable
File parameter in parameterized job
Prompted to upload it when running manually
Identifying parameters and how to use them: file parameter, string parameter
String parameter referred to by variable name ${TEST}
File parameter placed in the workspace in the parameter name
Promotions
Promotion of a job
Can run steps after a gate
Ex: archive artifacts, deploy, etc
CD Metrics
KPIs/metrics for CI/CD
Cycle time
Test coverage, cyclomatic complexity, duplication, etc
Number of defects
Velocity
# Commits per day
# Builds per day – success, failures and total
Duration of build
Notifications
How to radiate information on CD pipelines to teams
Email , radiator, etc
Chapter 4 – CD as Code Best Practices
Cloud slaves
EC2 for Amazon Cloud
JCloud – for other clouds
Containerization
Docker image to deploy/run application
“Build inside a Docker Container” option
Traceability
Docker Traceability plugin uses fingerprints for images
High availability
Master must be on network attached storage device
Don’t do builds on master or at least not with workspace under
JENKINS_HOME
HAProxy serves as the reverse proxy
Folders Plus
Features over folders plugin:
tie slaves to folders
move jobs between folders
health reports other than child with worst health (ex: average health, job
status, enabled projects)
set icons on folder other than default (ex: aggregate of status, built in icons or
by URL)
pass environment variables to all jobs in folder
display jobs from subfolders on higher level view
restrict what goes in folder
Templates
Types
o Auxiliary template – nested attributes within another template
o Builder/publisher template – locked down builder/publisher
o Folder/job template – configure folder/job
If define in folder, limited to that folder
Transformation types
o Jelly – has ${} and some control tags – like JSTL but different tags.
o Groovy template transformation – like a JSP in Groovy. Remember to
backslash $
o Groovy template for Pipleine
Variables instance, model, parent (Folder or Jenkins instance itself) and
parentInstance (the folder template where the job template sits)
When admin updates template, automatically approved. When non-admin
updates template, checked against whitelist of approved code or added to “in
process script approval” list for admin.
Groovy sandbox – can whitelist method signatures first time used. Format
method class.Name methodName argTypes (or static method). Admins use
whitelist too when sandbox on.
Creating with REST
o POST to /instantiate
o Or /createItem and specify JobPropertyImpl for template
Cloud configurations
Supports Docker, Amazon EC2 and Microsoft Azure clouds
Instance caps are managed on each master
Credentials shared across masters
Shared slaves
Client masters in the same CJOC can share slave executors
Client masters must be siblings or in same subfolder
Slaves are leased to client masters for one job if CJOC is available. If it goes
down, client master keeps slave until comes back.
Client masters prefer slaves in current “folder” then go to parent
Client masters are not allowed to use slaves at sibling folder level
Create shared slaves with CJOC
Analytics
Jenkins masters report data to CJOC
Display dashboards
Can create custom dashboards
To reindex and get historical data in CJOC
o new Cluster Operations job
o operation = masters
o target masters == from operations root
o step == reindex
Can run Elastic Search embedded or remote
Uses Kibana open source analytics and visualization platform
Includes System/JVM metrics, Web UI metrics, Jenkins metrics, health checks
Retention of data (reindexing resets clock)
o Every 10 seconds metrics – saved 3 days
o Hourly metrics – saved 3 years
o Build reporting – saved 3 years
o Other info saved forever
Cluster Operations
Used to performance maintenance operations from CJOC
Ways to run
o Checkbox on list view to prepare for shutdown or safe restart with left
navigation “cluster operations”
o Left navigation “cluster operations” on single master
o Cluster operations job
Each operation in job has:
o type = master or update center
o source = root, parent, parameter, etc
o optional filter on path, online status, etc
o steps
for master – Backup master, install/enable/disable plugin,
execute groovy script, prepare for shutdown, refresh update
center metadata, restart now, safe restart, upgrade jenkins,
upgrade all plugins
for update center – Delete/promote/update core,
delete/promote/update plugin, pull everything, pull new
versions, refresh upstream sources, track latest core, track
latest plugins
o advanced options
# parallel items
timeout per step
failure mode – immediately, tidy (at end of current step), at
end
build result to use on failure - unstable, failure, aborted
If you have multiple items to operate on, they will occur in parallel
Multi-branch
Benefits of Workflow Multi-Branch: automatic creation/deletion of job for
each new/deleted branch in repo
and configuring properties by branch
Uses marker file Jenkinsfile to define pipeline logic and recognize a job
should be created
Job gets deleted when branch or Jenkinsfile removed
Create new Multibranch Workflow job
Can give named branches different properties by specifying exceptions
Creates a folder for these jobs to exist in
Docker plugins
Docker is containers for deployment
Dockerhub (hub.docker.com) is like github – hosting for Docker
Plugins
o Docker – provision slave, run single build and then tear down that
slave
o Dockerhub notification - provides a hook so Docker can trigger
Jenkins jobs when the image is updated
o Docker build and registry - allows publishing to the Docker registry
o Docker traceability – history of deployments/images
o Docker pipeline provides docker variable to pipeline plugin
Examples:
o Build container: docker.build ‘path/app:${env.BUILD_TAG}’
o Run inside container: docker.image(‘name’).inside { /* commands */ }
o Reference container from outside in docker.withRun(‘name’).inside {
/* commands */ }