8. What is Jenkins Pipeline?
● Formerly known as Jenkins Workflow, Jenkins Pipeline was introduced in
2014
● New job type – a single Groovy script using an embedded DSL - no need to
jump between multiple job configuration screens to see what is going on
● Durable - keeps running even if Jenkins master is not
● Distributable – a Pipeline job may be run across an unlimited number of
nodes, including in parallel
● Pausable – allows waiting for input from users before continuing to the next
step
● Visualized - Pipeline Stage View provides status at-a-glance dashboards to
include trending
8
10. Install Jenkins Enterprise
10
Have Docker?
No Docker? No problem.
https://www.cloudbees.com/get-started
docker run -d -p 80:8080 --name cje -v
/var/run/docker.sock:/var/run/docker.sock beedemo/jenkins-
enterprise-trial
11. Finish Install
Unlock Jenkins
Request a trial license
Install suggested plugins
Create First Admin User
11
docker logs -f cje
Jenkins initial setup is required. An admin user has been created and a
password generated.
Please use the following password to proceed to installation:
1a90312e459b4d4693f18d48d102d6c6
14. Key Benefits
✓ Long-running
✓ Durable
✓ Scriptable
✓ One-place for Everything
Pipeline: a new job type
✓ Makes building Pipelines
Simple
15. Domain Specific Language
15
Simple, Groovy-based DSL (“Domain Specific Language”) to
manage build step orchestration
Can be defined as DSL in Jenkins or as Jenkinsfile in SCM
Groovy is widely used in Jenkins ecosystem. You can leverage
the large Jenkins Groovy experience
If you don’t like/care about Groovy, just consider the DSL as a
dedicated simple syntax
17. Create a Pipeline - core steps
17
stage - group your steps into its component parts and control
concurrency
node - schedules the steps to run by adding them to Jenkins'
build queue and creates a workspace specific to this pipeline
sh (or bat) - execute shell (*nix) or batch scripts (Windows)
just like freestyle jobs, calling any tools in the agent
18. Create a Pipeline
stage('build')
echo 'hello from jenkins master'
node {
sh 'echo hello from jenkins agent'
}
stage('test')
echo 'test some things'
stage('deploy')
echo 'deploy some things'
18
20. Files
stash - store some files for later use
unstash - retrieve previously stashed files (even across
nodes)
writeFile - write a file to the workspace
readFile - read a file from the workspace
20
22. try up to N times
retry(5) {
// some block
}
wait for a condition
waitUntil {
// some block
}
Flow Control
22
wait for a set time
sleep time: 1000, unit:'NANOSECONDS'
timeout
timeout(time: 30, unit: 'SECONDS'){
// some block
}
23. You can also rely on Groovy control flow syntax!
while(something) {
// do something
if (something_else) {
// do something else
}
}
Flow Control
23
try{
//some things
}catch(e){
//
}
24. Advanced Flow Control
input - pause for manual or automated approval
parallel - allows simultaneous execution of build steps on the current
node or across nodes, thus increasing build speed
parallel 'quality scan': {
node {sh 'mvn sonar:sonar'}
}, 'integration test': {
node {sh 'mvn verify'}
}
checkpoint - capture the workspace state so it can be reused
as a starting point for subsequent runs
29. tool Step
● Binds a tool installation to a variable
● The tool home directory is returned
● Only tools already configured are available
def mvnHome = tool 'M3'
sh "${mvnHome}/bin/mvn -B verify"
29
30. Use Docker Containers
● The CloudBees Docker Pipeline plugin allows running steps
inside a container
● You can even build the container as part of the same
Pipeline
docker.image('maven:3.3.3-jdk-8').inside() {
sh 'mvn -B verify'
}
30