3. What’s in it for me?
Pipeline helps to,
codify build flow
divide monolithic build
to logical stages
bind execution of one
or more stages based
on previous stage’s
result
abstract common tasks
to shared libraries
Learn Groovy DSL (scripted
syntax, shared libraries)
Declarative syntax follows
imperative model
Jenkins v2.x + Pipeline suite
of plugins
Tons and tons of patience to
toil, sweat a.k.a. R(ead),
A(pply), D(ocument) and
S(hare)
lots and lots of
Pre-requisites
https://www.flickr.com/photos/87232391@N00/403119696
4. Getting Started. . .
Have a test Jenkins master,
playground for trial and error
mirror (as close as possible) production instance
access to rest of infra or replicate where infra cannot be shared (e.g:
artifactory, s3, build agents)
mental model of what to do — logical blocks needed, how to tie them
up, what can or cannot be done in parallel, archive, notifications.
Tooo……ooons of material on the Internet on Jenkins Pipeline
5. Bite the bullet . . . Start writing pipeline as code
Start with individual stages, one stage at a time
Pipeline syntax and snippet generator
Pipeline script in <Version Control> => modify, build, test : repeat
Better yet, Replay on the passed or failed job
update on the fly, build, test
But, but, no Replay for builds failed on Groovy syntax :-(
6. Namaskara…
#!groovy
node(‘linux’) { // any build agent with label, linux;if left blank, master
stage(‘Prep’) {
def greet = “Welcome to Pipeline” // variable declaration
echo “${greet}”
sh “uname -a”
def ip_address = sh(returnStdout: true,
script: “ifconfig eth0 | grep -i inet | head -1 | awk -F’:’ ‘{print $2}’
| awk -F’ ‘ ‘{print $1}’”).trim()
println “Node’s IP address, ip_address”
}
}
7. Common Gotchas…
Pipeline syntax errors
DO NOT copy and paste from your editor or from the previous slide
Most common: Typos in pipeline code
Cautious with usage of Unix tools within Pipeline
single, double quotes
8. Got it finally…
#!groovy
node(‘linux’) { // build agent with label ‘linux’;if left blank,
master
stage("Prep") {
def greet = “Welcome to Pipeline" // variable declaration
echo "${greet}"
sh "uname -a"
sh "'/sbin/ifconfig eth0 |
grep -i inet | head -1 |
cut -d: -f2 |
awk -F' ' '{print $1}'
"'
}
sh step has many avatars
1. sh “command”
2. sh (returnStdout …)
3. sh (returnStatus …)
4. sh followed by three single or double quotes
(for variable interpolation)
Output from build console log
9. useful links
Online examples for various steps…
wiki => https://jenkins.io/doc/pipeline/examples/
code => https://github.com/jenkinsci/pipeline-examples/tree/master/
pipeline-examples
contribute your’s today, https://github.com/jenkinsci/pipeline-examples
Plugins compatible with Pipeline
https://github.com/jenkinsci/pipeline-plugin/blob/master/COMPATIBILITY.md
Pipeline resources
Syntax reference, https://jenkins.io/doc/book/pipeline/syntax
Steps reference, https://jenkins.io/doc/pipeline/steps
BlueOcean
https://jenkins.io/doc/book/blueocean
10. Handling SCM … Git
Have generic service accounts, avoid storing user credentials
Jenkins has built-in implementation of Git :-)
But, it may not be in sync with generally available version of Git :-(
Handling large Git repos in Jenkins
First 10mins from Jenkins online meetup video, https://www.youtube.com/
watch?v=TsWkZLLU-s4
https://www.cloudbees.com/blog/advanced-git-jenkins
General tips for handling large Git repos,
https://www.atlassian.com/blog/git/handle-big-repositories-git
https://larsxschneider.github.io/2016/09/21/large-git-repos