SlideShare a Scribd company logo
1 of 44
Download to read offline
TDD for Jenkins Pipelines
© 2018 All Rights Reserved. !2
*http://www.wyeside.co.uk
WHOAMI
#DevOps Engineer => #Solution Architect
#Core of DevOps engineer team
#CI/CD #Docker #K8s
#MakeLifeEasierForDevelopers
🐦 @ferratello
🌎 http://about.me/mauroferratello
© 2018 All Rights Reserved. !3
How do I feel now
https://commons.wikimedia.org/wiki/File:Spinecheek.jpg
© 2018 All Rights Reserved. !4
Once upon a time...
https://pixabay.com/en/castle-fairy-tales-nature-water-2064013/
... around 2011/2012
© 2018 All Rights Reserved. !5
It was a mess
• Not real CI
• build jobs made by brave volunteers
• nobody cares of the build status
https://pixabay.com/en/anarchy-political-social-rebellion-32917/¬
© 2018 All Rights Reserved. !6
Monolithic
application
• 2 or 3 releases/year
• deploy duration: 2 or 3 months
• n parallel branches
• urgent features straight in prod.
https://upload.wikimedia.org/wikipedia/commons/thumb/2/2f/095-pile-of-poo.svg/512px-095-pile-of-poo.svg.png
© 2018 All Rights Reserved. !7
Let's go to
microservices
https://upload.wikimedia.org/wikipedia/commons/thumb/2/2f/095-pile-of-poo.svg/512px-095-pile-of-poo.svg.png
© 2018 All Rights Reserved. !8
DevOps Anarchy
many different way to deploy something
https://pixabay.com/en/puzzle-unfinished-mess-unresolved-55879/
© 2018 All Rights Reserved. !9
we need a superhero!
http://pngimg.com/uploads/lego/lego_PNG29.png
...	Yes,	it's	me	😬
© 2018 All Rights Reserved. !10
Goal #1
One job to rule them all
https://www.flickr.com/photos/mk1971/1348204498
© 2018 All Rights Reserved. !11
Same tech stack
• Same server configuration
• Same application configuration
way
https://commons.wikimedia.org/wiki/File:Gorilla-server.svg
© 2018 All Rights Reserved. !12
D'oh!
Cannot access directly to
production server
http://pngimg.com/uploads/simpsons/simpsons_PNG94.png
© 2018 All Rights Reserved. !13
Workaround: dependency inversion
• Copy artifact on server
• Copy/change configuration o the
remote server
• execute remotely commands
Do Delegate
• Tell the server to download artifacts
from trusted repository
• Tell the server to upgrade
configuration from trusted repo
• Tell the server to deploy itself the
new artifact
vs
© 2018 All Rights Reserved. !14
We supposed
we solved all our problems
http://www.thebluediamondgallery.com/wooden-tile/h/happiness.html
© 2018 All Rights Reserved. !15
New needs
Custom request to deploy a JAR
not WAR
https://it.m.wikipedia.org/wiki/File:Question-mark-blackandwhite.png
© 2018 All Rights Reserved. !16
D'oh!
Regression Bugs!
http://pngimg.com/uploads/simpsons/simpsons_PNG94.png
© 2018 All Rights Reserved. !17
How to prevent?
• We need a way to test our code
• We need to run the test automatically after any change
© 2018 All Rights Reserved. !18
Why I have to test my final pipeline script?
• It's like test code only with e2e tests
• We have to repeat the same tests for all the pipelines
© 2018 All Rights Reserved. !19
Need #2
• Remove duplication
• Make pipelines simple for devs but robust at the same time
© 2018 All Rights Reserved. !20
#Global shared libraries!
https://www.pexels.com/photo/library-university-books-students-12064/
© 2018 All Rights Reserved. !21
Why?
• It's a way to avoid reinventing the wheel.
• They allow you to define your own library to share with all the pipeline scripts you use
• They allow you to reuse your code
• But most of all... you can test your libraries!
• https://jenkins.io/doc/book/pipeline/shared-libraries/
© 2018 All Rights Reserved. !22
How to use them?
• The "modern" way
• Libraries loaded dynamically
• Include only what you need

• I'm showing you this way 😉
@Libraryworkflow-libs
• The "old" way
• Libraries on the jenkins file system
• Loaded at jenkins startup
(sometimes with trouble)
• we followed this way 🤠
© 2018 All Rights Reserved. !23
Structure
© 2018 All Rights Reserved. !24
Step#1
• Move shared code into dedicated function (/vars)
© 2018 All Rights Reserved. !25
D'oh!
We can't test it locally
http://pngimg.com/uploads/simpsons/simpsons_PNG94.png
© 2018 All Rights Reserved. !26
Let's do OOP
Groovy objects
© 2018 All Rights Reserved. !27
Because we are "Clean Coders"
• SOLID principles
• Design
• Dependency injection
• etc...
• ...and TDD!
© 2018 All Rights Reserved. !28
Start easy
• A simple class to encode
parameters
© 2018 All Rights Reserved. !29
...and its unit tests
© 2018 All Rights Reserved. !30
That's so easy
But what about something more complicated?
And that needs jenkins pipeline steps?
https://jenkins.io/doc/pipeline/steps/
© 2018 All Rights Reserved. !31
D'oh!
• We can't access it inside
groovy classes
• We can't test it locally
http://pngimg.com/uploads/simpsons/simpsons_PNG94.png
© 2018 All Rights Reserved. !32
Reference
Pass "steps" as a reference in
constructor parameters
https://en.wikipedia.org/wiki/File:VisualEditor_-_Icon_-_add-reference.svg
© 2018 All Rights Reserved. !33
Example
• HttpClient
• "jenkins" is the reference
© 2018 All Rights Reserved. !34
Mock Objects
Let's mock as if there's no tomorrow
https://pixabay.com/en/fake-forgery-counterfeit-fraud-1726362/
© 2018 All Rights Reserved. !35
Example
• HttpClientTest
• "jenkins" is mocked
thanks to groovy
features
© 2018 All Rights Reserved. !36
Let's try it in
production...
• It's broken, due to an
unexpected behavior!
• pipelines broken for everyone!
• D'oh!
http://pngimg.com/uploads/simpsons/simpsons_PNG94.png
© 2018 All Rights Reserved. !37
We need Integration Test!
• They must be able to run
• LOCALLY
• on JENKINS
© 2018 All Rights Reserved. !38
Example of IntegrationTest on HTTP Client
© 2018 All Rights Reserved. !39
Locally we used Fake implementations
• We pass a fake instance of "steps" object to the test
• The fake object return the expected value so the test can pass even locally
• Alternatively the fake object can perform the same action with different
implementation (eg HttpRequest vs HttpURLConnection)
© 2018 All Rights Reserved. !40
Run on Jenkins
• in the pipeline the real jenkins "steps" is passed as a constructor parameter of the
test and real action is performed
• eg. for HTTPClient the real HttpRequest is used
© 2018 All Rights Reserved. !41
Pipeline with UT and IT running
© 2018 All Rights Reserved. !42
What we have seen:
✔ How to write simple unit tests
✔ How to write complex tests mocking jenkins steps
✔ How to write integration tests
✔ How to run unit test locally and on jenkins
✔ How to run integration test locally and on jenkins
.
.
.
✔ There's no silver bullet. Sometimes you have to accept compromises
Q&A
© 2018 All Rights Reserved. !44
References
• My sample repository: 

https://gitlab.com/Ferratello/jenkins-shared-libraries/
• Jenkins Global Shared Libraries :

https://jenkins.io/doc/book/pipeline/shared-libraries/
• Jenkins instance used to execute tests:

http://localhost:8080/
• I'm kidding 😬 but you can have your own simply running:

docker run -p 8080:8080 -v /local/path/for/jenkins_home:/var/jenkins_home jenkins/jenkins:alpine

More Related Content

What's hot

2016 Q1 - WebRTC testing State of The Art
2016 Q1 - WebRTC testing State of The Art2016 Q1 - WebRTC testing State of The Art
2016 Q1 - WebRTC testing State of The ArtAlexandre Gouaillard
 
Continuous Integration
Continuous IntegrationContinuous Integration
Continuous IntegrationKelli Mohr
 
和艦長一起玩轉 GitLab & GitLab Workflow
和艦長一起玩轉 GitLab & GitLab Workflow和艦長一起玩轉 GitLab & GitLab Workflow
和艦長一起玩轉 GitLab & GitLab WorkflowChen Cheng-Wei
 
Lightweight continuous delivery for small schools
Lightweight continuous delivery for small schoolsLightweight continuous delivery for small schools
Lightweight continuous delivery for small schoolsCharles Fulton
 
GitOps is IaC done right
GitOps is IaC done rightGitOps is IaC done right
GitOps is IaC done rightChen Cheng-Wei
 
Prepare to defend thyself with Blue/Green
Prepare to defend thyself with Blue/GreenPrepare to defend thyself with Blue/Green
Prepare to defend thyself with Blue/GreenSonatype
 
DevOps Training - Ho Chi Minh City
DevOps Training - Ho Chi Minh CityDevOps Training - Ho Chi Minh City
DevOps Training - Ho Chi Minh CityChristian Trabold
 
CI doesn’t start with Jenkins
CI doesn’t start with JenkinsCI doesn’t start with Jenkins
CI doesn’t start with JenkinsYuriy Rochnyak
 
Succesful testing-continuous-delivery-testnet
Succesful testing-continuous-delivery-testnetSuccesful testing-continuous-delivery-testnet
Succesful testing-continuous-delivery-testnetHarald Rietman
 
2016 February - WebRTC Conference japan - English
2016 February - WebRTC Conference japan - English2016 February - WebRTC Conference japan - English
2016 February - WebRTC Conference japan - EnglishAlexandre Gouaillard
 
OSGi Versioning & Testing
OSGi Versioning & TestingOSGi Versioning & Testing
OSGi Versioning & TestingChris Aniszczyk
 
GitLab 8.5 Highlights and Step-by-step tutorial
GitLab 8.5 Highlights and Step-by-step tutorialGitLab 8.5 Highlights and Step-by-step tutorial
GitLab 8.5 Highlights and Step-by-step tutorialHeather McNamee
 
vodQA Pune (2019) - Jenkins pipeline As code
vodQA Pune (2019) - Jenkins pipeline As codevodQA Pune (2019) - Jenkins pipeline As code
vodQA Pune (2019) - Jenkins pipeline As codevodQA
 
Building A Distributed Build System at Google Scale (StrangeLoop 2016)
Building A Distributed Build System at Google Scale (StrangeLoop 2016)Building A Distributed Build System at Google Scale (StrangeLoop 2016)
Building A Distributed Build System at Google Scale (StrangeLoop 2016)Aysylu Greenberg
 
Collaborating on GitHub for Open Source Documentation
Collaborating on GitHub for Open Source DocumentationCollaborating on GitHub for Open Source Documentation
Collaborating on GitHub for Open Source DocumentationAnne Gentle
 

What's hot (20)

2016 Q1 - WebRTC testing State of The Art
2016 Q1 - WebRTC testing State of The Art2016 Q1 - WebRTC testing State of The Art
2016 Q1 - WebRTC testing State of The Art
 
Continuous Integration
Continuous IntegrationContinuous Integration
Continuous Integration
 
Gerrit Code Review
Gerrit Code ReviewGerrit Code Review
Gerrit Code Review
 
和艦長一起玩轉 GitLab & GitLab Workflow
和艦長一起玩轉 GitLab & GitLab Workflow和艦長一起玩轉 GitLab & GitLab Workflow
和艦長一起玩轉 GitLab & GitLab Workflow
 
Lightweight continuous delivery for small schools
Lightweight continuous delivery for small schoolsLightweight continuous delivery for small schools
Lightweight continuous delivery for small schools
 
Git essentials
Git essentialsGit essentials
Git essentials
 
GitOps is IaC done right
GitOps is IaC done rightGitOps is IaC done right
GitOps is IaC done right
 
Prepare to defend thyself with Blue/Green
Prepare to defend thyself with Blue/GreenPrepare to defend thyself with Blue/Green
Prepare to defend thyself with Blue/Green
 
DevOps Training - Ho Chi Minh City
DevOps Training - Ho Chi Minh CityDevOps Training - Ho Chi Minh City
DevOps Training - Ho Chi Minh City
 
CI doesn’t start with Jenkins
CI doesn’t start with JenkinsCI doesn’t start with Jenkins
CI doesn’t start with Jenkins
 
Succesful testing-continuous-delivery-testnet
Succesful testing-continuous-delivery-testnetSuccesful testing-continuous-delivery-testnet
Succesful testing-continuous-delivery-testnet
 
Gerrit Workshop
Gerrit WorkshopGerrit Workshop
Gerrit Workshop
 
Gitlab CI/CD
Gitlab CI/CDGitlab CI/CD
Gitlab CI/CD
 
2016 February - WebRTC Conference japan - English
2016 February - WebRTC Conference japan - English2016 February - WebRTC Conference japan - English
2016 February - WebRTC Conference japan - English
 
OSGi Versioning & Testing
OSGi Versioning & TestingOSGi Versioning & Testing
OSGi Versioning & Testing
 
GitLab 8.5 Highlights and Step-by-step tutorial
GitLab 8.5 Highlights and Step-by-step tutorialGitLab 8.5 Highlights and Step-by-step tutorial
GitLab 8.5 Highlights and Step-by-step tutorial
 
vodQA Pune (2019) - Jenkins pipeline As code
vodQA Pune (2019) - Jenkins pipeline As codevodQA Pune (2019) - Jenkins pipeline As code
vodQA Pune (2019) - Jenkins pipeline As code
 
Building A Distributed Build System at Google Scale (StrangeLoop 2016)
Building A Distributed Build System at Google Scale (StrangeLoop 2016)Building A Distributed Build System at Google Scale (StrangeLoop 2016)
Building A Distributed Build System at Google Scale (StrangeLoop 2016)
 
Collaborating on GitHub for Open Source Documentation
Collaborating on GitHub for Open Source DocumentationCollaborating on GitHub for Open Source Documentation
Collaborating on GitHub for Open Source Documentation
 
Project52
Project52Project52
Project52
 

Similar to TDD for jenkins pipelines

Road to NODES - Blazing Fast Ingest with Apache Arrow
Road to NODES - Blazing Fast Ingest with Apache ArrowRoad to NODES - Blazing Fast Ingest with Apache Arrow
Road to NODES - Blazing Fast Ingest with Apache ArrowNeo4j
 
Building the Pipeline of My Dreams
Building the Pipeline of My DreamsBuilding the Pipeline of My Dreams
Building the Pipeline of My DreamsGene Gotimer
 
OpenRheinRuhr 2018 - Ops hates containers! Why?
OpenRheinRuhr 2018 - Ops hates containers! Why?OpenRheinRuhr 2018 - Ops hates containers! Why?
OpenRheinRuhr 2018 - Ops hates containers! Why?Martin Alfke
 
Building CI from scratch
Building CI from scratchBuilding CI from scratch
Building CI from scratchArtem Nikitin
 
What is cool with Domino V10, Proton and Node.JS, and why would I use it in ...
What is cool with Domino V10, Proton and Node.JS, and why would I use it in ...What is cool with Domino V10, Proton and Node.JS, and why would I use it in ...
What is cool with Domino V10, Proton and Node.JS, and why would I use it in ...Heiko Voigt
 
[2020 git lab commit] continuous infrastructure
[2020 git lab commit] continuous infrastructure[2020 git lab commit] continuous infrastructure
[2020 git lab commit] continuous infrastructureRodrigo Stefani Domingues
 
Emulators as an Emerging Best Practice for API Providers
Emulators as an Emerging Best Practice for API ProvidersEmulators as an Emerging Best Practice for API Providers
Emulators as an Emerging Best Practice for API ProvidersCisco DevNet
 
Introduction to Web Components & Polymer Workshop - JS Interactive
Introduction to Web Components & Polymer Workshop - JS InteractiveIntroduction to Web Components & Polymer Workshop - JS Interactive
Introduction to Web Components & Polymer Workshop - JS InteractiveJohn Riviello
 
Tridens DevOps
Tridens DevOpsTridens DevOps
Tridens DevOpsTridens
 
Shrinking the container_zurich_july_2018
Shrinking the container_zurich_july_2018Shrinking the container_zurich_july_2018
Shrinking the container_zurich_july_2018Ewan Slater
 
Angular v2 et plus : le futur du développement d'applications en entreprise
Angular v2 et plus : le futur du développement d'applications en entrepriseAngular v2 et plus : le futur du développement d'applications en entreprise
Angular v2 et plus : le futur du développement d'applications en entrepriseLINAGORA
 
Why use Go for web development?
Why use Go for web development?Why use Go for web development?
Why use Go for web development?Weng Wei
 
DEVNET-2006 Coding 210: Parsing JSON in C++
DEVNET-2006	Coding 210: Parsing JSON in C++DEVNET-2006	Coding 210: Parsing JSON in C++
DEVNET-2006 Coding 210: Parsing JSON in C++Cisco DevNet
 
Использование AzureDevOps при разработке микросервисных приложений
Использование AzureDevOps при разработке микросервисных приложенийИспользование AzureDevOps при разработке микросервисных приложений
Использование AzureDevOps при разработке микросервисных приложенийVitebsk Miniq
 
Hadoop Demystified + Automation Smackdown! Austin JUG June 24 2014
Hadoop Demystified + Automation Smackdown!  Austin JUG June 24 2014Hadoop Demystified + Automation Smackdown!  Austin JUG June 24 2014
Hadoop Demystified + Automation Smackdown! Austin JUG June 24 2014datafundamentals
 
[KubeCon NA 2018] Effective Kubernetes Develop: Turbocharge Your Dev Loop - P...
[KubeCon NA 2018] Effective Kubernetes Develop: Turbocharge Your Dev Loop - P...[KubeCon NA 2018] Effective Kubernetes Develop: Turbocharge Your Dev Loop - P...
[KubeCon NA 2018] Effective Kubernetes Develop: Turbocharge Your Dev Loop - P...Ambassador Labs
 
Progressive Enhancement using WSGI
Progressive Enhancement using WSGIProgressive Enhancement using WSGI
Progressive Enhancement using WSGIMatthew Wilkes
 

Similar to TDD for jenkins pipelines (20)

Road to NODES - Blazing Fast Ingest with Apache Arrow
Road to NODES - Blazing Fast Ingest with Apache ArrowRoad to NODES - Blazing Fast Ingest with Apache Arrow
Road to NODES - Blazing Fast Ingest with Apache Arrow
 
Building the Pipeline of My Dreams
Building the Pipeline of My DreamsBuilding the Pipeline of My Dreams
Building the Pipeline of My Dreams
 
OpenRheinRuhr 2018 - Ops hates containers! Why?
OpenRheinRuhr 2018 - Ops hates containers! Why?OpenRheinRuhr 2018 - Ops hates containers! Why?
OpenRheinRuhr 2018 - Ops hates containers! Why?
 
Building CI from scratch
Building CI from scratchBuilding CI from scratch
Building CI from scratch
 
What is cool with Domino V10, Proton and Node.JS, and why would I use it in ...
What is cool with Domino V10, Proton and Node.JS, and why would I use it in ...What is cool with Domino V10, Proton and Node.JS, and why would I use it in ...
What is cool with Domino V10, Proton and Node.JS, and why would I use it in ...
 
[2020 git lab commit] continuous infrastructure
[2020 git lab commit] continuous infrastructure[2020 git lab commit] continuous infrastructure
[2020 git lab commit] continuous infrastructure
 
Emulators as an Emerging Best Practice for API Providers
Emulators as an Emerging Best Practice for API ProvidersEmulators as an Emerging Best Practice for API Providers
Emulators as an Emerging Best Practice for API Providers
 
Introduction to Web Components & Polymer Workshop - JS Interactive
Introduction to Web Components & Polymer Workshop - JS InteractiveIntroduction to Web Components & Polymer Workshop - JS Interactive
Introduction to Web Components & Polymer Workshop - JS Interactive
 
Tridens DevOps
Tridens DevOpsTridens DevOps
Tridens DevOps
 
Shrinking the container_zurich_july_2018
Shrinking the container_zurich_july_2018Shrinking the container_zurich_july_2018
Shrinking the container_zurich_july_2018
 
From Heroku to Amazon AWS
From Heroku to Amazon AWSFrom Heroku to Amazon AWS
From Heroku to Amazon AWS
 
Angular v2 et plus : le futur du développement d'applications en entreprise
Angular v2 et plus : le futur du développement d'applications en entrepriseAngular v2 et plus : le futur du développement d'applications en entreprise
Angular v2 et plus : le futur du développement d'applications en entreprise
 
Angelique henry performance non regression
Angelique henry   performance non regressionAngelique henry   performance non regression
Angelique henry performance non regression
 
Why use Go for web development?
Why use Go for web development?Why use Go for web development?
Why use Go for web development?
 
DEVNET-2006 Coding 210: Parsing JSON in C++
DEVNET-2006	Coding 210: Parsing JSON in C++DEVNET-2006	Coding 210: Parsing JSON in C++
DEVNET-2006 Coding 210: Parsing JSON in C++
 
Использование AzureDevOps при разработке микросервисных приложений
Использование AzureDevOps при разработке микросервисных приложенийИспользование AzureDevOps при разработке микросервисных приложений
Использование AzureDevOps при разработке микросервисных приложений
 
Hadoop Demystified + Automation Smackdown! Austin JUG June 24 2014
Hadoop Demystified + Automation Smackdown!  Austin JUG June 24 2014Hadoop Demystified + Automation Smackdown!  Austin JUG June 24 2014
Hadoop Demystified + Automation Smackdown! Austin JUG June 24 2014
 
Docker for Developers
Docker for DevelopersDocker for Developers
Docker for Developers
 
[KubeCon NA 2018] Effective Kubernetes Develop: Turbocharge Your Dev Loop - P...
[KubeCon NA 2018] Effective Kubernetes Develop: Turbocharge Your Dev Loop - P...[KubeCon NA 2018] Effective Kubernetes Develop: Turbocharge Your Dev Loop - P...
[KubeCon NA 2018] Effective Kubernetes Develop: Turbocharge Your Dev Loop - P...
 
Progressive Enhancement using WSGI
Progressive Enhancement using WSGIProgressive Enhancement using WSGI
Progressive Enhancement using WSGI
 

Recently uploaded

WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...WSO2
 
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...Shane Coughlan
 
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...SelfMade bd
 
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfonteinmasabamasaba
 
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...WSO2
 
WSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
WSO2Con2024 - Enabling Transactional System's Exponential Growth With SimplicityWSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
WSO2Con2024 - Enabling Transactional System's Exponential Growth With SimplicityWSO2
 
Announcing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK SoftwareAnnouncing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK SoftwareJim McKeeth
 
tonesoftg
tonesoftgtonesoftg
tonesoftglanshi9
 
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...masabamasaba
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsArshad QA
 
WSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go PlatformlessWSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go PlatformlessWSO2
 
%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Harare%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Hararemasabamasaba
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension AidPhilip Schwarz
 
8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech studentsHimanshiGarg82
 
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...Bert Jan Schrijver
 
The title is not connected to what is inside
The title is not connected to what is insideThe title is not connected to what is inside
The title is not connected to what is insideshinachiaurasa2
 
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...Jittipong Loespradit
 
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfonteinmasabamasaba
 

Recently uploaded (20)

WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
 
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
 
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
 
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
 
WSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
WSO2Con2024 - Enabling Transactional System's Exponential Growth With SimplicityWSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
WSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
 
Announcing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK SoftwareAnnouncing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK Software
 
tonesoftg
tonesoftgtonesoftg
tonesoftg
 
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 
WSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go PlatformlessWSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go Platformless
 
%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Harare%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Harare
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
 
8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students
 
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
 
The title is not connected to what is inside
The title is not connected to what is insideThe title is not connected to what is inside
The title is not connected to what is inside
 
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
 
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 

TDD for jenkins pipelines

  • 1. TDD for Jenkins Pipelines
  • 2. © 2018 All Rights Reserved. !2 *http://www.wyeside.co.uk WHOAMI #DevOps Engineer => #Solution Architect #Core of DevOps engineer team #CI/CD #Docker #K8s #MakeLifeEasierForDevelopers 🐦 @ferratello 🌎 http://about.me/mauroferratello
  • 3. © 2018 All Rights Reserved. !3 How do I feel now https://commons.wikimedia.org/wiki/File:Spinecheek.jpg
  • 4. © 2018 All Rights Reserved. !4 Once upon a time... https://pixabay.com/en/castle-fairy-tales-nature-water-2064013/ ... around 2011/2012
  • 5. © 2018 All Rights Reserved. !5 It was a mess • Not real CI • build jobs made by brave volunteers • nobody cares of the build status https://pixabay.com/en/anarchy-political-social-rebellion-32917/¬
  • 6. © 2018 All Rights Reserved. !6 Monolithic application • 2 or 3 releases/year • deploy duration: 2 or 3 months • n parallel branches • urgent features straight in prod. https://upload.wikimedia.org/wikipedia/commons/thumb/2/2f/095-pile-of-poo.svg/512px-095-pile-of-poo.svg.png
  • 7. © 2018 All Rights Reserved. !7 Let's go to microservices https://upload.wikimedia.org/wikipedia/commons/thumb/2/2f/095-pile-of-poo.svg/512px-095-pile-of-poo.svg.png
  • 8. © 2018 All Rights Reserved. !8 DevOps Anarchy many different way to deploy something https://pixabay.com/en/puzzle-unfinished-mess-unresolved-55879/
  • 9. © 2018 All Rights Reserved. !9 we need a superhero! http://pngimg.com/uploads/lego/lego_PNG29.png ... Yes, it's me 😬
  • 10. © 2018 All Rights Reserved. !10 Goal #1 One job to rule them all https://www.flickr.com/photos/mk1971/1348204498
  • 11. © 2018 All Rights Reserved. !11 Same tech stack • Same server configuration • Same application configuration way https://commons.wikimedia.org/wiki/File:Gorilla-server.svg
  • 12. © 2018 All Rights Reserved. !12 D'oh! Cannot access directly to production server http://pngimg.com/uploads/simpsons/simpsons_PNG94.png
  • 13. © 2018 All Rights Reserved. !13 Workaround: dependency inversion • Copy artifact on server • Copy/change configuration o the remote server • execute remotely commands Do Delegate • Tell the server to download artifacts from trusted repository • Tell the server to upgrade configuration from trusted repo • Tell the server to deploy itself the new artifact vs
  • 14. © 2018 All Rights Reserved. !14 We supposed we solved all our problems http://www.thebluediamondgallery.com/wooden-tile/h/happiness.html
  • 15. © 2018 All Rights Reserved. !15 New needs Custom request to deploy a JAR not WAR https://it.m.wikipedia.org/wiki/File:Question-mark-blackandwhite.png
  • 16. © 2018 All Rights Reserved. !16 D'oh! Regression Bugs! http://pngimg.com/uploads/simpsons/simpsons_PNG94.png
  • 17. © 2018 All Rights Reserved. !17 How to prevent? • We need a way to test our code • We need to run the test automatically after any change
  • 18. © 2018 All Rights Reserved. !18 Why I have to test my final pipeline script? • It's like test code only with e2e tests • We have to repeat the same tests for all the pipelines
  • 19. © 2018 All Rights Reserved. !19 Need #2 • Remove duplication • Make pipelines simple for devs but robust at the same time
  • 20. © 2018 All Rights Reserved. !20 #Global shared libraries! https://www.pexels.com/photo/library-university-books-students-12064/
  • 21. © 2018 All Rights Reserved. !21 Why? • It's a way to avoid reinventing the wheel. • They allow you to define your own library to share with all the pipeline scripts you use • They allow you to reuse your code • But most of all... you can test your libraries! • https://jenkins.io/doc/book/pipeline/shared-libraries/
  • 22. © 2018 All Rights Reserved. !22 How to use them? • The "modern" way • Libraries loaded dynamically • Include only what you need
 • I'm showing you this way 😉 @Libraryworkflow-libs • The "old" way • Libraries on the jenkins file system • Loaded at jenkins startup (sometimes with trouble) • we followed this way 🤠
  • 23. © 2018 All Rights Reserved. !23 Structure
  • 24. © 2018 All Rights Reserved. !24 Step#1 • Move shared code into dedicated function (/vars)
  • 25. © 2018 All Rights Reserved. !25 D'oh! We can't test it locally http://pngimg.com/uploads/simpsons/simpsons_PNG94.png
  • 26. © 2018 All Rights Reserved. !26 Let's do OOP Groovy objects
  • 27. © 2018 All Rights Reserved. !27 Because we are "Clean Coders" • SOLID principles • Design • Dependency injection • etc... • ...and TDD!
  • 28. © 2018 All Rights Reserved. !28 Start easy • A simple class to encode parameters
  • 29. © 2018 All Rights Reserved. !29 ...and its unit tests
  • 30. © 2018 All Rights Reserved. !30 That's so easy But what about something more complicated? And that needs jenkins pipeline steps? https://jenkins.io/doc/pipeline/steps/
  • 31. © 2018 All Rights Reserved. !31 D'oh! • We can't access it inside groovy classes • We can't test it locally http://pngimg.com/uploads/simpsons/simpsons_PNG94.png
  • 32. © 2018 All Rights Reserved. !32 Reference Pass "steps" as a reference in constructor parameters https://en.wikipedia.org/wiki/File:VisualEditor_-_Icon_-_add-reference.svg
  • 33. © 2018 All Rights Reserved. !33 Example • HttpClient • "jenkins" is the reference
  • 34. © 2018 All Rights Reserved. !34 Mock Objects Let's mock as if there's no tomorrow https://pixabay.com/en/fake-forgery-counterfeit-fraud-1726362/
  • 35. © 2018 All Rights Reserved. !35 Example • HttpClientTest • "jenkins" is mocked thanks to groovy features
  • 36. © 2018 All Rights Reserved. !36 Let's try it in production... • It's broken, due to an unexpected behavior! • pipelines broken for everyone! • D'oh! http://pngimg.com/uploads/simpsons/simpsons_PNG94.png
  • 37. © 2018 All Rights Reserved. !37 We need Integration Test! • They must be able to run • LOCALLY • on JENKINS
  • 38. © 2018 All Rights Reserved. !38 Example of IntegrationTest on HTTP Client
  • 39. © 2018 All Rights Reserved. !39 Locally we used Fake implementations • We pass a fake instance of "steps" object to the test • The fake object return the expected value so the test can pass even locally • Alternatively the fake object can perform the same action with different implementation (eg HttpRequest vs HttpURLConnection)
  • 40. © 2018 All Rights Reserved. !40 Run on Jenkins • in the pipeline the real jenkins "steps" is passed as a constructor parameter of the test and real action is performed • eg. for HTTPClient the real HttpRequest is used
  • 41. © 2018 All Rights Reserved. !41 Pipeline with UT and IT running
  • 42. © 2018 All Rights Reserved. !42 What we have seen: ✔ How to write simple unit tests ✔ How to write complex tests mocking jenkins steps ✔ How to write integration tests ✔ How to run unit test locally and on jenkins ✔ How to run integration test locally and on jenkins . . . ✔ There's no silver bullet. Sometimes you have to accept compromises
  • 43. Q&A
  • 44. © 2018 All Rights Reserved. !44 References • My sample repository: 
 https://gitlab.com/Ferratello/jenkins-shared-libraries/ • Jenkins Global Shared Libraries :
 https://jenkins.io/doc/book/pipeline/shared-libraries/ • Jenkins instance used to execute tests:
 http://localhost:8080/ • I'm kidding 😬 but you can have your own simply running:
 docker run -p 8080:8080 -v /local/path/for/jenkins_home:/var/jenkins_home jenkins/jenkins:alpine