SlideShare a Scribd company logo
Jenkins
In search of best practices
Kuleshov Dmitry
DevOps TechLead
Lohika
https://www.linkedin.com/in/vdksystem
Whoami
Why Jenkins?
What is it about…
Jenkins pipelines
Ø Scripted
Ø Declarative
Shared libraries
Ø In general
Ø src
Ø vars
Ø Combined
Ø MPL
JCasC
Conclusion
1. One of top 10 CI/CD tools
2. Still in trends
Why Jenkins?
Scripted Declarative
VS
node {
stage('Hello') {
echo 'Hello World!'
}
}
pipeline {
agent any
stages {
stage('Hello') {
steps {
echo 'Hello World'
}
}
}
}
Scripted Declarative
VS
node {
try {
…
} catch(e) {
switch(currentBuild.status) {
case “SUCCESS”: …;
case “FAILURE”: …;
}
} finally {
…
}
}
pipeline {
…
post {
always {
…
}
success {
…
}
…
}
}
• Syntax Checking
– Immediate runtime syntax checking with explicit error messages.
– API and CLI ability for linting a Jenkinsfile.
• Docker and Kubernetes Pipeline integration
– Run all stages in a single container.
– Run each stage in a different container.
• Easy configuration
– Quickly define parameters for your Pipeline.
– Quickly define environment variables and credentials for your Pipeline.
– Quickly define options (such as timeout, retry, build discarding) for your Pipeline.
• Conditional actions
– Send notifications or take actions depending upon success or failure.
– Skip stages based on branches, environment, or other Boolean expression.
Declarative Pipeline Features
Tremendous amount of flexibility
Scripted Pipeline Features
• Making sure to use Groovy code in Pipelines as glue
• Avoiding complex Groovy code
• Reducing repetition of similar Pipeline steps
• Be careful with Concurrency
• Avoiding calls to Jenkins.getInstance
Pipeline best practices
Templated Pipeline
appPipeline {
unitTests = true,
sonar = true,
…
}
def call(body) {
def config = [:]
body.resolveStrategy = Closure.DELEGATE_FIRST
body.delegate = config
body()
…
}
Shared libraries
• Customer wants to use it
• Don’t repeat yourself
• Custom steps
• Jenkinsfile is too large
• Lots of microservices with the same type
• Jenkins as a SAAS (e.g. multy-team)
When do we need Shared library
General best practices:
• Do not override built-in Pipeline steps
• Avoiding large global variable declaration files
• Avoiding very large shared libraries
• Using @NonCPS
• Versioning shared libraries
• Do not reinvent the wheel
Shared library best practices
Shared library - src
class Pipeline
config
build
test…
class customPipeline extends Pipeline
build
test
// Jenkinsfile
@Library('utils') import org.foo.customPipeline
def p = new customPipeline(this)
node {
stage(“Build”) {
p.build()
}
}
Shared library - src
// src/org/foo/Utilities.groovy
package org.foo
class Utilities implements Serializable {
def steps
Utilities(steps) {this.steps = steps}
def mvn(args) {
steps.sh "${steps.tool 'Maven'}/bin/mvn -o ${args}"
}
}
Shared library - src
// src/org/foo/Zot.groovy
package org.foo
def checkOutFrom(repo) {
git url: "git@github.com:jenkinsci/${repo}"
}
return this
// Jenkinsfile
@Library('utils') import org.foo.Zot
node {
def z = new org.foo.Zot()
z.checkOutFrom(repo)
}
Shared library - vars
// vars/gitCheckout.groovy
def call(repo) {
git url: "git@github.com:jenkinsci/${repo}"
}
// vars/gitTools.groovy
def checkout(repo) {
git url: "git@github.com:jenkinsci/${repo}"
}
// Jenkinsfile
@Library('utils’) _
node {
stage(“Checkout”) {
gitCheckout(“repo URL”)
// or
gitTools.checkout(“repo URL”)
}
}
Shared library - vars
(root)
+- src/org/foo
| +- GlobalVars.groovy
+- vars
| +- helm.groovy
| +- helm.txt
| +- maven.groovy
| +- maven.txt
| +- utils.groovy
| +- utils.txt
+- resources
| +- org
| +- foo
| +- bar.json
@Library(‘lib’) _
node {
stage(“Checkout”) {
utils.checkout(“repo URL”)
}
stage(“Package”) {
maven.package()
}
stage(“Deploy”) {
helm.deploy()
}
}
Shared library - config
// src/org/foo/GlobalVars.groovy
package org.foo
class GlobalConfig {
public static defaults = [
"k8s" : [
"dev": [
"clusterUrl": "k8s.local",
"credentialsId": "k8s-dev-access"
],
"stg": […]
]
]
}
// vars/k8s.groovy
import static org.foo.GlobalConfig.defaults
def apply(filePath, env = ‘dev’) {
def credentialsId = defaults.k8s[env]. credentialsId
def serverUrl = defaults.k8s[env]. serverUrl
withKubeConfig([credentialsId: credentialsId, serverUrl: clusterUrl]) {
sh ”kubectl apply -f ${filePath}"
}
}
Shared library - config
// vars/fooPipeline.groovy
import static org.foo.GlobalConfig.defaults
def call(body) {
def config = [:]
body.resolveStrategy = Closure.DELEGATE_FIRST
body.delegate = config
body()
def cfg = defaults << config
pipeline {…}
}
// Jenkinsfile
fooPipeline{
k8s = [
dev: [
clusterUrl: ‘k8s.cluster.notlocal’,
credentialsId: ‘notlocal-credentials’
]
]
}
Jenkins Configuration as Code
JCasC
unclassified:
globalLibraries:
libraries:
- defaultVersion: "master"
includeInChangesets: false
name: "jsl"
jenkins:
clouds:
- kubernetes:
containerCapStr: "10"
jenkinsTunnel: "jenkins-agent:50000"
jenkinsUrl: "http://jenkins:8080"
name: "kubernetes"
jenkins:
systemMessage: "Jenkins configured as Code”
• Standard component of the Jenkins project
• Schema validation
• Vault integration
• JobDSL for jobs declaration
• Dynamic config reload
• Doesn’t support plugin installation
JCasC
Demo
• Keep it easy to read and maintain
• Use declarative pipelines
• Keep pipeline logic in Jenkinsfile
• Use shared library only if it’s really required
• Write custom steps in vars, don’t forget .txt
• Join methods by tool (log, helm, maven, etc)
• Check plugins first
• Cleanup everything as part of pipeline
• Read documentation
Conclusion
• kubernetes
• kubernetes-credentials-provider
• pipeline-utility-steps
• github-organization-folder
• cloudbees-bitbucket-branch-source
• bitbucket-filter-project-trait
• job-dsl
• blueocean
• prometheus
• timestamper
• rebuild
Useful plugins
• https://jenkins.io/doc/pipeline/steps/
• https://jenkins.io/doc/book/pipeline/shared-libraries/
• https://github.com/griddynamics/mpl
• https://jenkins.io/doc/book/pipeline/pipeline-best-practices/
• http://aimtheory.com/jenkins/pipeline/continuous-delivery/2018/10/01/jenkins-pipeline-global-
shared-library-best-practices-part-2.html
• https://bmuschko.com/blog/jenkins-shared-libraries/
• https://medium.com/@werne2j/unit-testing-a-jenkins-shared-library-9bfb6b599748
https://github.com/jenkinsci/configuration-as-code-plugin
• https://github.com/jenkinsci/configuration-as-code-plugin/tree/master/demos
• https://github.com/vdksystem/techtalkjenkins-jsl
• https://github.com/vdksystem/techtalkjenkins
Links
Thank You!

More Related Content

What's hot

Ninja Build: Simple Guide for Beginners
Ninja Build: Simple Guide for BeginnersNinja Build: Simple Guide for Beginners
Ninja Build: Simple Guide for Beginners
Chang W. Doh
 
Pipeline as code - new feature in Jenkins 2
Pipeline as code - new feature in Jenkins 2Pipeline as code - new feature in Jenkins 2
Pipeline as code - new feature in Jenkins 2
Michal Ziarnik
 
Pragmatic Monolith-First, easy to decompose, clean architecture
Pragmatic Monolith-First, easy to decompose, clean architecturePragmatic Monolith-First, easy to decompose, clean architecture
Pragmatic Monolith-First, easy to decompose, clean architecture
Piotr Pelczar
 
Let's go HTTPS-only! - More Than Buying a Certificate
Let's go HTTPS-only! - More Than Buying a CertificateLet's go HTTPS-only! - More Than Buying a Certificate
Let's go HTTPS-only! - More Than Buying a Certificate
Steffen Gebert
 
Kubernetes deep dive - - Huawei 2015-10
Kubernetes deep dive - - Huawei 2015-10Kubernetes deep dive - - Huawei 2015-10
Kubernetes deep dive - - Huawei 2015-10
Vishnu Kannan
 
Lesson Learned from Using Docker Swarm at Pronto
Lesson Learned from Using Docker Swarm at ProntoLesson Learned from Using Docker Swarm at Pronto
Lesson Learned from Using Docker Swarm at Pronto
Kan Ouivirach, Ph.D.
 
JavaOne 2016 - Pipeline as code
JavaOne 2016 - Pipeline as codeJavaOne 2016 - Pipeline as code
JavaOne 2016 - Pipeline as code
Bert Jan Schrijver
 
Scala, docker and testing, oh my! mario camou
Scala, docker and testing, oh my! mario camouScala, docker and testing, oh my! mario camou
Scala, docker and testing, oh my! mario camou
J On The Beach
 
GradleFX
GradleFXGradleFX
Monitoring Containers at New Relic by Sean Kane
Monitoring Containers at New Relic by Sean Kane Monitoring Containers at New Relic by Sean Kane
Monitoring Containers at New Relic by Sean Kane
Docker, Inc.
 
Dockerizing Windows Server Applications by Ender Barillas and Taylor Brown
Dockerizing Windows Server Applications by Ender Barillas and Taylor BrownDockerizing Windows Server Applications by Ender Barillas and Taylor Brown
Dockerizing Windows Server Applications by Ender Barillas and Taylor Brown
Docker, Inc.
 
10 Cool Facts about Gradle
10 Cool Facts about Gradle10 Cool Facts about Gradle
10 Cool Facts about GradleEvgeny Goldin
 
Container Orchestration from Theory to Practice
Container Orchestration from Theory to PracticeContainer Orchestration from Theory to Practice
Container Orchestration from Theory to Practice
Docker, Inc.
 
Kubernetes Node Deep Dive
Kubernetes Node Deep DiveKubernetes Node Deep Dive
Kubernetes Node Deep Dive
Lei (Harry) Zhang
 
The (mutable) config management showdown
The (mutable) config management showdownThe (mutable) config management showdown
The (mutable) config management showdown
Bob Killen
 
Docker for Developers - php[tek] 2017
Docker for Developers - php[tek] 2017Docker for Developers - php[tek] 2017
Docker for Developers - php[tek] 2017
Chris Tankersley
 
Kubernetes intro public - kubernetes meetup 4-21-2015
Kubernetes intro   public - kubernetes meetup 4-21-2015Kubernetes intro   public - kubernetes meetup 4-21-2015
Kubernetes intro public - kubernetes meetup 4-21-2015
Rohit Jnagal
 
Docker d2 박승환
Docker d2 박승환Docker d2 박승환
Docker d2 박승환
Seunghwan Park
 
Docker for Fun and Profit
Docker for Fun and ProfitDocker for Fun and Profit
Docker for Fun and Profit
Kel Cecil
 
Observability in a Dynamically Scheduled World
Observability in a Dynamically Scheduled WorldObservability in a Dynamically Scheduled World
Observability in a Dynamically Scheduled World
Sneha Inguva
 

What's hot (20)

Ninja Build: Simple Guide for Beginners
Ninja Build: Simple Guide for BeginnersNinja Build: Simple Guide for Beginners
Ninja Build: Simple Guide for Beginners
 
Pipeline as code - new feature in Jenkins 2
Pipeline as code - new feature in Jenkins 2Pipeline as code - new feature in Jenkins 2
Pipeline as code - new feature in Jenkins 2
 
Pragmatic Monolith-First, easy to decompose, clean architecture
Pragmatic Monolith-First, easy to decompose, clean architecturePragmatic Monolith-First, easy to decompose, clean architecture
Pragmatic Monolith-First, easy to decompose, clean architecture
 
Let's go HTTPS-only! - More Than Buying a Certificate
Let's go HTTPS-only! - More Than Buying a CertificateLet's go HTTPS-only! - More Than Buying a Certificate
Let's go HTTPS-only! - More Than Buying a Certificate
 
Kubernetes deep dive - - Huawei 2015-10
Kubernetes deep dive - - Huawei 2015-10Kubernetes deep dive - - Huawei 2015-10
Kubernetes deep dive - - Huawei 2015-10
 
Lesson Learned from Using Docker Swarm at Pronto
Lesson Learned from Using Docker Swarm at ProntoLesson Learned from Using Docker Swarm at Pronto
Lesson Learned from Using Docker Swarm at Pronto
 
JavaOne 2016 - Pipeline as code
JavaOne 2016 - Pipeline as codeJavaOne 2016 - Pipeline as code
JavaOne 2016 - Pipeline as code
 
Scala, docker and testing, oh my! mario camou
Scala, docker and testing, oh my! mario camouScala, docker and testing, oh my! mario camou
Scala, docker and testing, oh my! mario camou
 
GradleFX
GradleFXGradleFX
GradleFX
 
Monitoring Containers at New Relic by Sean Kane
Monitoring Containers at New Relic by Sean Kane Monitoring Containers at New Relic by Sean Kane
Monitoring Containers at New Relic by Sean Kane
 
Dockerizing Windows Server Applications by Ender Barillas and Taylor Brown
Dockerizing Windows Server Applications by Ender Barillas and Taylor BrownDockerizing Windows Server Applications by Ender Barillas and Taylor Brown
Dockerizing Windows Server Applications by Ender Barillas and Taylor Brown
 
10 Cool Facts about Gradle
10 Cool Facts about Gradle10 Cool Facts about Gradle
10 Cool Facts about Gradle
 
Container Orchestration from Theory to Practice
Container Orchestration from Theory to PracticeContainer Orchestration from Theory to Practice
Container Orchestration from Theory to Practice
 
Kubernetes Node Deep Dive
Kubernetes Node Deep DiveKubernetes Node Deep Dive
Kubernetes Node Deep Dive
 
The (mutable) config management showdown
The (mutable) config management showdownThe (mutable) config management showdown
The (mutable) config management showdown
 
Docker for Developers - php[tek] 2017
Docker for Developers - php[tek] 2017Docker for Developers - php[tek] 2017
Docker for Developers - php[tek] 2017
 
Kubernetes intro public - kubernetes meetup 4-21-2015
Kubernetes intro   public - kubernetes meetup 4-21-2015Kubernetes intro   public - kubernetes meetup 4-21-2015
Kubernetes intro public - kubernetes meetup 4-21-2015
 
Docker d2 박승환
Docker d2 박승환Docker d2 박승환
Docker d2 박승환
 
Docker for Fun and Profit
Docker for Fun and ProfitDocker for Fun and Profit
Docker for Fun and Profit
 
Observability in a Dynamically Scheduled World
Observability in a Dynamically Scheduled WorldObservability in a Dynamically Scheduled World
Observability in a Dynamically Scheduled World
 

Similar to DevOps Odessa #TechTalks 21.01.2020

Jenkins Pipelines
Jenkins PipelinesJenkins Pipelines
Jenkins Pipelines
Steffen Gebert
 
Dev ops meetup
Dev ops meetupDev ops meetup
Dev ops meetup
Bigdata Meetup Kochi
 
(Declarative) Jenkins Pipelines
(Declarative) Jenkins Pipelines(Declarative) Jenkins Pipelines
(Declarative) Jenkins Pipelines
Steffen Gebert
 
An Open-Source Chef Cookbook CI/CD Implementation Using Jenkins Pipelines
An Open-Source Chef Cookbook CI/CD Implementation Using Jenkins PipelinesAn Open-Source Chef Cookbook CI/CD Implementation Using Jenkins Pipelines
An Open-Source Chef Cookbook CI/CD Implementation Using Jenkins Pipelines
Steffen Gebert
 
Gradleintroduction 111010130329-phpapp01
Gradleintroduction 111010130329-phpapp01Gradleintroduction 111010130329-phpapp01
Gradleintroduction 111010130329-phpapp01Tino Isnich
 
Gradle
GradleGradle
Atlanta Jenkins Area Meetup October 22nd 2015
Atlanta Jenkins Area Meetup October 22nd 2015Atlanta Jenkins Area Meetup October 22nd 2015
Atlanta Jenkins Area Meetup October 22nd 2015
Kurt Madel
 
Apache DeltaSpike
Apache DeltaSpikeApache DeltaSpike
Apache DeltaSpikeos890
 
Introduction to JIB and Google Cloud Run
Introduction to JIB and Google Cloud RunIntroduction to JIB and Google Cloud Run
Introduction to JIB and Google Cloud Run
Saiyam Pathak
 
Antons Kranga Building Agile Infrastructures
Antons Kranga   Building Agile InfrastructuresAntons Kranga   Building Agile Infrastructures
Antons Kranga Building Agile Infrastructures
Antons Kranga
 
KubeCon EU 2016: Leveraging ephemeral namespaces in a CI/CD pipeline
KubeCon EU 2016: Leveraging ephemeral namespaces in a CI/CD pipelineKubeCon EU 2016: Leveraging ephemeral namespaces in a CI/CD pipeline
KubeCon EU 2016: Leveraging ephemeral namespaces in a CI/CD pipeline
KubeAcademy
 
Jenkins days workshop pipelines - Eric Long
Jenkins days workshop  pipelines - Eric LongJenkins days workshop  pipelines - Eric Long
Jenkins days workshop pipelines - Eric Long
ericlongtx
 
Testcontainers - Geekout EE 2017 presentation
Testcontainers - Geekout EE 2017 presentationTestcontainers - Geekout EE 2017 presentation
Testcontainers - Geekout EE 2017 presentation
Richard North
 
Integration tests: use the containers, Luke!
Integration tests: use the containers, Luke!Integration tests: use the containers, Luke!
Integration tests: use the containers, Luke!
Roberto Franchini
 
Docker 102 - Immutable Infrastructure
Docker 102 - Immutable InfrastructureDocker 102 - Immutable Infrastructure
Docker 102 - Immutable Infrastructure
Adrian Otto
 
The Docker "Gauntlet" - Introduction, Ecosystem, Deployment, Orchestration
The Docker "Gauntlet" - Introduction, Ecosystem, Deployment, OrchestrationThe Docker "Gauntlet" - Introduction, Ecosystem, Deployment, Orchestration
The Docker "Gauntlet" - Introduction, Ecosystem, Deployment, Orchestration
Erica Windisch
 
Plugin-based software design with Ruby and RubyGems
Plugin-based software design with Ruby and RubyGemsPlugin-based software design with Ruby and RubyGems
Plugin-based software design with Ruby and RubyGems
Sadayuki Furuhashi
 
DevOPS training - Day 2/2
DevOPS training - Day 2/2DevOPS training - Day 2/2
DevOPS training - Day 2/2
Vincent Mercier
 
Testing the Enterprise Layers - the A, B, C's of Integration Testing - Aslak ...
Testing the Enterprise Layers - the A, B, C's of Integration Testing - Aslak ...Testing the Enterprise Layers - the A, B, C's of Integration Testing - Aslak ...
Testing the Enterprise Layers - the A, B, C's of Integration Testing - Aslak ...
JAXLondon2014
 

Similar to DevOps Odessa #TechTalks 21.01.2020 (20)

Jenkins Pipelines
Jenkins PipelinesJenkins Pipelines
Jenkins Pipelines
 
Dev ops meetup
Dev ops meetupDev ops meetup
Dev ops meetup
 
(Declarative) Jenkins Pipelines
(Declarative) Jenkins Pipelines(Declarative) Jenkins Pipelines
(Declarative) Jenkins Pipelines
 
An Open-Source Chef Cookbook CI/CD Implementation Using Jenkins Pipelines
An Open-Source Chef Cookbook CI/CD Implementation Using Jenkins PipelinesAn Open-Source Chef Cookbook CI/CD Implementation Using Jenkins Pipelines
An Open-Source Chef Cookbook CI/CD Implementation Using Jenkins Pipelines
 
Gradle Introduction
Gradle IntroductionGradle Introduction
Gradle Introduction
 
Gradleintroduction 111010130329-phpapp01
Gradleintroduction 111010130329-phpapp01Gradleintroduction 111010130329-phpapp01
Gradleintroduction 111010130329-phpapp01
 
Gradle
GradleGradle
Gradle
 
Atlanta Jenkins Area Meetup October 22nd 2015
Atlanta Jenkins Area Meetup October 22nd 2015Atlanta Jenkins Area Meetup October 22nd 2015
Atlanta Jenkins Area Meetup October 22nd 2015
 
Apache DeltaSpike
Apache DeltaSpikeApache DeltaSpike
Apache DeltaSpike
 
Introduction to JIB and Google Cloud Run
Introduction to JIB and Google Cloud RunIntroduction to JIB and Google Cloud Run
Introduction to JIB and Google Cloud Run
 
Antons Kranga Building Agile Infrastructures
Antons Kranga   Building Agile InfrastructuresAntons Kranga   Building Agile Infrastructures
Antons Kranga Building Agile Infrastructures
 
KubeCon EU 2016: Leveraging ephemeral namespaces in a CI/CD pipeline
KubeCon EU 2016: Leveraging ephemeral namespaces in a CI/CD pipelineKubeCon EU 2016: Leveraging ephemeral namespaces in a CI/CD pipeline
KubeCon EU 2016: Leveraging ephemeral namespaces in a CI/CD pipeline
 
Jenkins days workshop pipelines - Eric Long
Jenkins days workshop  pipelines - Eric LongJenkins days workshop  pipelines - Eric Long
Jenkins days workshop pipelines - Eric Long
 
Testcontainers - Geekout EE 2017 presentation
Testcontainers - Geekout EE 2017 presentationTestcontainers - Geekout EE 2017 presentation
Testcontainers - Geekout EE 2017 presentation
 
Integration tests: use the containers, Luke!
Integration tests: use the containers, Luke!Integration tests: use the containers, Luke!
Integration tests: use the containers, Luke!
 
Docker 102 - Immutable Infrastructure
Docker 102 - Immutable InfrastructureDocker 102 - Immutable Infrastructure
Docker 102 - Immutable Infrastructure
 
The Docker "Gauntlet" - Introduction, Ecosystem, Deployment, Orchestration
The Docker "Gauntlet" - Introduction, Ecosystem, Deployment, OrchestrationThe Docker "Gauntlet" - Introduction, Ecosystem, Deployment, Orchestration
The Docker "Gauntlet" - Introduction, Ecosystem, Deployment, Orchestration
 
Plugin-based software design with Ruby and RubyGems
Plugin-based software design with Ruby and RubyGemsPlugin-based software design with Ruby and RubyGems
Plugin-based software design with Ruby and RubyGems
 
DevOPS training - Day 2/2
DevOPS training - Day 2/2DevOPS training - Day 2/2
DevOPS training - Day 2/2
 
Testing the Enterprise Layers - the A, B, C's of Integration Testing - Aslak ...
Testing the Enterprise Layers - the A, B, C's of Integration Testing - Aslak ...Testing the Enterprise Layers - the A, B, C's of Integration Testing - Aslak ...
Testing the Enterprise Layers - the A, B, C's of Integration Testing - Aslak ...
 

More from Lohika_Odessa_TechTalks

OAuth2 Authorization Server Under the Hood
OAuth2 Authorization Server Under the HoodOAuth2 Authorization Server Under the Hood
OAuth2 Authorization Server Under the Hood
Lohika_Odessa_TechTalks
 
Debugging Microservices - key challenges and techniques - Microservices Odesa...
Debugging Microservices - key challenges and techniques - Microservices Odesa...Debugging Microservices - key challenges and techniques - Microservices Odesa...
Debugging Microservices - key challenges and techniques - Microservices Odesa...
Lohika_Odessa_TechTalks
 
Design and Evolution of APIs in Microservice Architecture
Design and Evolution of APIs in Microservice ArchitectureDesign and Evolution of APIs in Microservice Architecture
Design and Evolution of APIs in Microservice Architecture
Lohika_Odessa_TechTalks
 
Micro-frontends – is it a new normal?
Micro-frontends – is it a new normal?Micro-frontends – is it a new normal?
Micro-frontends – is it a new normal?
Lohika_Odessa_TechTalks
 
Multithreading in go
Multithreading in goMultithreading in go
Multithreading in go
Lohika_Odessa_TechTalks
 
Druid - Interactive Analytics At Scale
Druid - Interactive Analytics At ScaleDruid - Interactive Analytics At Scale
Druid - Interactive Analytics At Scale
Lohika_Odessa_TechTalks
 
Architectural peripherals of react by Vadym Zhiltsov
Architectural peripherals of react by Vadym ZhiltsovArchitectural peripherals of react by Vadym Zhiltsov
Architectural peripherals of react by Vadym Zhiltsov
Lohika_Odessa_TechTalks
 
React native by example by Vadim Ruban
React native by example by Vadim RubanReact native by example by Vadim Ruban
React native by example by Vadim Ruban
Lohika_Odessa_TechTalks
 
Aws lambda by Leonid Amigud
Aws lambda by Leonid AmigudAws lambda by Leonid Amigud
Aws lambda by Leonid Amigud
Lohika_Odessa_TechTalks
 
Congratulations, you have been promoted to a manager role. You`ve got new pro...
Congratulations, you have been promoted to a manager role. You`ve got new pro...Congratulations, you have been promoted to a manager role. You`ve got new pro...
Congratulations, you have been promoted to a manager role. You`ve got new pro...
Lohika_Odessa_TechTalks
 
"Don't touch me and give me my money" or how motivate people who can but don...
"Don't touch me and give me my money" or  how motivate people who can but don..."Don't touch me and give me my money" or  how motivate people who can but don...
"Don't touch me and give me my money" or how motivate people who can but don...
Lohika_Odessa_TechTalks
 
Docker based Architecture by Denys Serdiuk
Docker based Architecture by Denys SerdiukDocker based Architecture by Denys Serdiuk
Docker based Architecture by Denys Serdiuk
Lohika_Odessa_TechTalks
 
SparkSpark in the Big Data dark by Sergey Levandovskiy
SparkSpark in the Big Data dark by Sergey Levandovskiy  SparkSpark in the Big Data dark by Sergey Levandovskiy
SparkSpark in the Big Data dark by Sergey Levandovskiy
Lohika_Odessa_TechTalks
 
Burnout and how to avoid it in your team. Responsible person's issue by Andre...
Burnout and how to avoid it in your team. Responsible person's issue by Andre...Burnout and how to avoid it in your team. Responsible person's issue by Andre...
Burnout and how to avoid it in your team. Responsible person's issue by Andre...
Lohika_Odessa_TechTalks
 
Performance evaluation process as a way to empower your employees and help th...
Performance evaluation process as a way to empower your employees and help th...Performance evaluation process as a way to empower your employees and help th...
Performance evaluation process as a way to empower your employees and help th...
Lohika_Odessa_TechTalks
 
Selenium with py test by Alexandr Vasyliev for Lohika Odessa Python TechTalks
Selenium with py test by Alexandr Vasyliev for Lohika Odessa Python TechTalksSelenium with py test by Alexandr Vasyliev for Lohika Odessa Python TechTalks
Selenium with py test by Alexandr Vasyliev for Lohika Odessa Python TechTalks
Lohika_Odessa_TechTalks
 
" Performance testing for Automation QA - why and how " by Andrey Kovalenko f...
" Performance testing for Automation QA - why and how " by Andrey Kovalenko f..." Performance testing for Automation QA - why and how " by Andrey Kovalenko f...
" Performance testing for Automation QA - why and how " by Andrey Kovalenko f...
Lohika_Odessa_TechTalks
 
"WEB applications security testing" by Kirill Semenov for Lohika Odessa QA Te...
"WEB applications security testing" by Kirill Semenov for Lohika Odessa QA Te..."WEB applications security testing" by Kirill Semenov for Lohika Odessa QA Te...
"WEB applications security testing" by Kirill Semenov for Lohika Odessa QA Te...
Lohika_Odessa_TechTalks
 
Developing Rest services with SailsJs by Andrey Kolodnitskiy
Developing Rest services with SailsJs by Andrey KolodnitskiyDeveloping Rest services with SailsJs by Andrey Kolodnitskiy
Developing Rest services with SailsJs by Andrey Kolodnitskiy
Lohika_Odessa_TechTalks
 
JavaScript Design Patterns overview by Ksenia Redunova
JavaScript Design Patterns overview by Ksenia RedunovaJavaScript Design Patterns overview by Ksenia Redunova
JavaScript Design Patterns overview by Ksenia Redunova
Lohika_Odessa_TechTalks
 

More from Lohika_Odessa_TechTalks (20)

OAuth2 Authorization Server Under the Hood
OAuth2 Authorization Server Under the HoodOAuth2 Authorization Server Under the Hood
OAuth2 Authorization Server Under the Hood
 
Debugging Microservices - key challenges and techniques - Microservices Odesa...
Debugging Microservices - key challenges and techniques - Microservices Odesa...Debugging Microservices - key challenges and techniques - Microservices Odesa...
Debugging Microservices - key challenges and techniques - Microservices Odesa...
 
Design and Evolution of APIs in Microservice Architecture
Design and Evolution of APIs in Microservice ArchitectureDesign and Evolution of APIs in Microservice Architecture
Design and Evolution of APIs in Microservice Architecture
 
Micro-frontends – is it a new normal?
Micro-frontends – is it a new normal?Micro-frontends – is it a new normal?
Micro-frontends – is it a new normal?
 
Multithreading in go
Multithreading in goMultithreading in go
Multithreading in go
 
Druid - Interactive Analytics At Scale
Druid - Interactive Analytics At ScaleDruid - Interactive Analytics At Scale
Druid - Interactive Analytics At Scale
 
Architectural peripherals of react by Vadym Zhiltsov
Architectural peripherals of react by Vadym ZhiltsovArchitectural peripherals of react by Vadym Zhiltsov
Architectural peripherals of react by Vadym Zhiltsov
 
React native by example by Vadim Ruban
React native by example by Vadim RubanReact native by example by Vadim Ruban
React native by example by Vadim Ruban
 
Aws lambda by Leonid Amigud
Aws lambda by Leonid AmigudAws lambda by Leonid Amigud
Aws lambda by Leonid Amigud
 
Congratulations, you have been promoted to a manager role. You`ve got new pro...
Congratulations, you have been promoted to a manager role. You`ve got new pro...Congratulations, you have been promoted to a manager role. You`ve got new pro...
Congratulations, you have been promoted to a manager role. You`ve got new pro...
 
"Don't touch me and give me my money" or how motivate people who can but don...
"Don't touch me and give me my money" or  how motivate people who can but don..."Don't touch me and give me my money" or  how motivate people who can but don...
"Don't touch me and give me my money" or how motivate people who can but don...
 
Docker based Architecture by Denys Serdiuk
Docker based Architecture by Denys SerdiukDocker based Architecture by Denys Serdiuk
Docker based Architecture by Denys Serdiuk
 
SparkSpark in the Big Data dark by Sergey Levandovskiy
SparkSpark in the Big Data dark by Sergey Levandovskiy  SparkSpark in the Big Data dark by Sergey Levandovskiy
SparkSpark in the Big Data dark by Sergey Levandovskiy
 
Burnout and how to avoid it in your team. Responsible person's issue by Andre...
Burnout and how to avoid it in your team. Responsible person's issue by Andre...Burnout and how to avoid it in your team. Responsible person's issue by Andre...
Burnout and how to avoid it in your team. Responsible person's issue by Andre...
 
Performance evaluation process as a way to empower your employees and help th...
Performance evaluation process as a way to empower your employees and help th...Performance evaluation process as a way to empower your employees and help th...
Performance evaluation process as a way to empower your employees and help th...
 
Selenium with py test by Alexandr Vasyliev for Lohika Odessa Python TechTalks
Selenium with py test by Alexandr Vasyliev for Lohika Odessa Python TechTalksSelenium with py test by Alexandr Vasyliev for Lohika Odessa Python TechTalks
Selenium with py test by Alexandr Vasyliev for Lohika Odessa Python TechTalks
 
" Performance testing for Automation QA - why and how " by Andrey Kovalenko f...
" Performance testing for Automation QA - why and how " by Andrey Kovalenko f..." Performance testing for Automation QA - why and how " by Andrey Kovalenko f...
" Performance testing for Automation QA - why and how " by Andrey Kovalenko f...
 
"WEB applications security testing" by Kirill Semenov for Lohika Odessa QA Te...
"WEB applications security testing" by Kirill Semenov for Lohika Odessa QA Te..."WEB applications security testing" by Kirill Semenov for Lohika Odessa QA Te...
"WEB applications security testing" by Kirill Semenov for Lohika Odessa QA Te...
 
Developing Rest services with SailsJs by Andrey Kolodnitskiy
Developing Rest services with SailsJs by Andrey KolodnitskiyDeveloping Rest services with SailsJs by Andrey Kolodnitskiy
Developing Rest services with SailsJs by Andrey Kolodnitskiy
 
JavaScript Design Patterns overview by Ksenia Redunova
JavaScript Design Patterns overview by Ksenia RedunovaJavaScript Design Patterns overview by Ksenia Redunova
JavaScript Design Patterns overview by Ksenia Redunova
 

Recently uploaded

Bitcoin Lightning wallet and tic-tac-toe game XOXO
Bitcoin Lightning wallet and tic-tac-toe game XOXOBitcoin Lightning wallet and tic-tac-toe game XOXO
Bitcoin Lightning wallet and tic-tac-toe game XOXO
Matjaž Lipuš
 
Announcement of 18th IEEE International Conference on Software Testing, Verif...
Announcement of 18th IEEE International Conference on Software Testing, Verif...Announcement of 18th IEEE International Conference on Software Testing, Verif...
Announcement of 18th IEEE International Conference on Software Testing, Verif...
Sebastiano Panichella
 
Obesity causes and management and associated medical conditions
Obesity causes and management and associated medical conditionsObesity causes and management and associated medical conditions
Obesity causes and management and associated medical conditions
Faculty of Medicine And Health Sciences
 
0x01 - Newton's Third Law: Static vs. Dynamic Abusers
0x01 - Newton's Third Law:  Static vs. Dynamic Abusers0x01 - Newton's Third Law:  Static vs. Dynamic Abusers
0x01 - Newton's Third Law: Static vs. Dynamic Abusers
OWASP Beja
 
Competition and Regulation in Professional Services – KLEINER – June 2024 OEC...
Competition and Regulation in Professional Services – KLEINER – June 2024 OEC...Competition and Regulation in Professional Services – KLEINER – June 2024 OEC...
Competition and Regulation in Professional Services – KLEINER – June 2024 OEC...
OECD Directorate for Financial and Enterprise Affairs
 
Bonzo subscription_hjjjjjjjj5hhhhhhh_2024.pdf
Bonzo subscription_hjjjjjjjj5hhhhhhh_2024.pdfBonzo subscription_hjjjjjjjj5hhhhhhh_2024.pdf
Bonzo subscription_hjjjjjjjj5hhhhhhh_2024.pdf
khadija278284
 
Getting started with Amazon Bedrock Studio and Control Tower
Getting started with Amazon Bedrock Studio and Control TowerGetting started with Amazon Bedrock Studio and Control Tower
Getting started with Amazon Bedrock Studio and Control Tower
Vladimir Samoylov
 
Doctoral Symposium at the 17th IEEE International Conference on Software Test...
Doctoral Symposium at the 17th IEEE International Conference on Software Test...Doctoral Symposium at the 17th IEEE International Conference on Software Test...
Doctoral Symposium at the 17th IEEE International Conference on Software Test...
Sebastiano Panichella
 
International Workshop on Artificial Intelligence in Software Testing
International Workshop on Artificial Intelligence in Software TestingInternational Workshop on Artificial Intelligence in Software Testing
International Workshop on Artificial Intelligence in Software Testing
Sebastiano Panichella
 
Sharpen existing tools or get a new toolbox? Contemporary cluster initiatives...
Sharpen existing tools or get a new toolbox? Contemporary cluster initiatives...Sharpen existing tools or get a new toolbox? Contemporary cluster initiatives...
Sharpen existing tools or get a new toolbox? Contemporary cluster initiatives...
Orkestra
 
Acorn Recovery: Restore IT infra within minutes
Acorn Recovery: Restore IT infra within minutesAcorn Recovery: Restore IT infra within minutes
Acorn Recovery: Restore IT infra within minutes
IP ServerOne
 
somanykidsbutsofewfathers-140705000023-phpapp02.pptx
somanykidsbutsofewfathers-140705000023-phpapp02.pptxsomanykidsbutsofewfathers-140705000023-phpapp02.pptx
somanykidsbutsofewfathers-140705000023-phpapp02.pptx
Howard Spence
 
Eureka, I found it! - Special Libraries Association 2021 Presentation
Eureka, I found it! - Special Libraries Association 2021 PresentationEureka, I found it! - Special Libraries Association 2021 Presentation
Eureka, I found it! - Special Libraries Association 2021 Presentation
Access Innovations, Inc.
 

Recently uploaded (13)

Bitcoin Lightning wallet and tic-tac-toe game XOXO
Bitcoin Lightning wallet and tic-tac-toe game XOXOBitcoin Lightning wallet and tic-tac-toe game XOXO
Bitcoin Lightning wallet and tic-tac-toe game XOXO
 
Announcement of 18th IEEE International Conference on Software Testing, Verif...
Announcement of 18th IEEE International Conference on Software Testing, Verif...Announcement of 18th IEEE International Conference on Software Testing, Verif...
Announcement of 18th IEEE International Conference on Software Testing, Verif...
 
Obesity causes and management and associated medical conditions
Obesity causes and management and associated medical conditionsObesity causes and management and associated medical conditions
Obesity causes and management and associated medical conditions
 
0x01 - Newton's Third Law: Static vs. Dynamic Abusers
0x01 - Newton's Third Law:  Static vs. Dynamic Abusers0x01 - Newton's Third Law:  Static vs. Dynamic Abusers
0x01 - Newton's Third Law: Static vs. Dynamic Abusers
 
Competition and Regulation in Professional Services – KLEINER – June 2024 OEC...
Competition and Regulation in Professional Services – KLEINER – June 2024 OEC...Competition and Regulation in Professional Services – KLEINER – June 2024 OEC...
Competition and Regulation in Professional Services – KLEINER – June 2024 OEC...
 
Bonzo subscription_hjjjjjjjj5hhhhhhh_2024.pdf
Bonzo subscription_hjjjjjjjj5hhhhhhh_2024.pdfBonzo subscription_hjjjjjjjj5hhhhhhh_2024.pdf
Bonzo subscription_hjjjjjjjj5hhhhhhh_2024.pdf
 
Getting started with Amazon Bedrock Studio and Control Tower
Getting started with Amazon Bedrock Studio and Control TowerGetting started with Amazon Bedrock Studio and Control Tower
Getting started with Amazon Bedrock Studio and Control Tower
 
Doctoral Symposium at the 17th IEEE International Conference on Software Test...
Doctoral Symposium at the 17th IEEE International Conference on Software Test...Doctoral Symposium at the 17th IEEE International Conference on Software Test...
Doctoral Symposium at the 17th IEEE International Conference on Software Test...
 
International Workshop on Artificial Intelligence in Software Testing
International Workshop on Artificial Intelligence in Software TestingInternational Workshop on Artificial Intelligence in Software Testing
International Workshop on Artificial Intelligence in Software Testing
 
Sharpen existing tools or get a new toolbox? Contemporary cluster initiatives...
Sharpen existing tools or get a new toolbox? Contemporary cluster initiatives...Sharpen existing tools or get a new toolbox? Contemporary cluster initiatives...
Sharpen existing tools or get a new toolbox? Contemporary cluster initiatives...
 
Acorn Recovery: Restore IT infra within minutes
Acorn Recovery: Restore IT infra within minutesAcorn Recovery: Restore IT infra within minutes
Acorn Recovery: Restore IT infra within minutes
 
somanykidsbutsofewfathers-140705000023-phpapp02.pptx
somanykidsbutsofewfathers-140705000023-phpapp02.pptxsomanykidsbutsofewfathers-140705000023-phpapp02.pptx
somanykidsbutsofewfathers-140705000023-phpapp02.pptx
 
Eureka, I found it! - Special Libraries Association 2021 Presentation
Eureka, I found it! - Special Libraries Association 2021 PresentationEureka, I found it! - Special Libraries Association 2021 Presentation
Eureka, I found it! - Special Libraries Association 2021 Presentation
 

DevOps Odessa #TechTalks 21.01.2020

  • 1. Jenkins In search of best practices
  • 3. Why Jenkins? What is it about… Jenkins pipelines Ø Scripted Ø Declarative Shared libraries Ø In general Ø src Ø vars Ø Combined Ø MPL JCasC Conclusion
  • 4. 1. One of top 10 CI/CD tools 2. Still in trends Why Jenkins?
  • 5. Scripted Declarative VS node { stage('Hello') { echo 'Hello World!' } } pipeline { agent any stages { stage('Hello') { steps { echo 'Hello World' } } } }
  • 6. Scripted Declarative VS node { try { … } catch(e) { switch(currentBuild.status) { case “SUCCESS”: …; case “FAILURE”: …; } } finally { … } } pipeline { … post { always { … } success { … } … } }
  • 7. • Syntax Checking – Immediate runtime syntax checking with explicit error messages. – API and CLI ability for linting a Jenkinsfile. • Docker and Kubernetes Pipeline integration – Run all stages in a single container. – Run each stage in a different container. • Easy configuration – Quickly define parameters for your Pipeline. – Quickly define environment variables and credentials for your Pipeline. – Quickly define options (such as timeout, retry, build discarding) for your Pipeline. • Conditional actions – Send notifications or take actions depending upon success or failure. – Skip stages based on branches, environment, or other Boolean expression. Declarative Pipeline Features
  • 8. Tremendous amount of flexibility Scripted Pipeline Features
  • 9. • Making sure to use Groovy code in Pipelines as glue • Avoiding complex Groovy code • Reducing repetition of similar Pipeline steps • Be careful with Concurrency • Avoiding calls to Jenkins.getInstance Pipeline best practices
  • 10. Templated Pipeline appPipeline { unitTests = true, sonar = true, … } def call(body) { def config = [:] body.resolveStrategy = Closure.DELEGATE_FIRST body.delegate = config body() … }
  • 12. • Customer wants to use it • Don’t repeat yourself • Custom steps • Jenkinsfile is too large • Lots of microservices with the same type • Jenkins as a SAAS (e.g. multy-team) When do we need Shared library
  • 13. General best practices: • Do not override built-in Pipeline steps • Avoiding large global variable declaration files • Avoiding very large shared libraries • Using @NonCPS • Versioning shared libraries • Do not reinvent the wheel Shared library best practices
  • 14. Shared library - src class Pipeline config build test… class customPipeline extends Pipeline build test // Jenkinsfile @Library('utils') import org.foo.customPipeline def p = new customPipeline(this) node { stage(“Build”) { p.build() } }
  • 15. Shared library - src // src/org/foo/Utilities.groovy package org.foo class Utilities implements Serializable { def steps Utilities(steps) {this.steps = steps} def mvn(args) { steps.sh "${steps.tool 'Maven'}/bin/mvn -o ${args}" } }
  • 16. Shared library - src // src/org/foo/Zot.groovy package org.foo def checkOutFrom(repo) { git url: "git@github.com:jenkinsci/${repo}" } return this // Jenkinsfile @Library('utils') import org.foo.Zot node { def z = new org.foo.Zot() z.checkOutFrom(repo) }
  • 17. Shared library - vars // vars/gitCheckout.groovy def call(repo) { git url: "git@github.com:jenkinsci/${repo}" } // vars/gitTools.groovy def checkout(repo) { git url: "git@github.com:jenkinsci/${repo}" } // Jenkinsfile @Library('utils’) _ node { stage(“Checkout”) { gitCheckout(“repo URL”) // or gitTools.checkout(“repo URL”) } }
  • 18. Shared library - vars (root) +- src/org/foo | +- GlobalVars.groovy +- vars | +- helm.groovy | +- helm.txt | +- maven.groovy | +- maven.txt | +- utils.groovy | +- utils.txt +- resources | +- org | +- foo | +- bar.json @Library(‘lib’) _ node { stage(“Checkout”) { utils.checkout(“repo URL”) } stage(“Package”) { maven.package() } stage(“Deploy”) { helm.deploy() } }
  • 19. Shared library - config // src/org/foo/GlobalVars.groovy package org.foo class GlobalConfig { public static defaults = [ "k8s" : [ "dev": [ "clusterUrl": "k8s.local", "credentialsId": "k8s-dev-access" ], "stg": […] ] ] } // vars/k8s.groovy import static org.foo.GlobalConfig.defaults def apply(filePath, env = ‘dev’) { def credentialsId = defaults.k8s[env]. credentialsId def serverUrl = defaults.k8s[env]. serverUrl withKubeConfig([credentialsId: credentialsId, serverUrl: clusterUrl]) { sh ”kubectl apply -f ${filePath}" } }
  • 20. Shared library - config // vars/fooPipeline.groovy import static org.foo.GlobalConfig.defaults def call(body) { def config = [:] body.resolveStrategy = Closure.DELEGATE_FIRST body.delegate = config body() def cfg = defaults << config pipeline {…} } // Jenkinsfile fooPipeline{ k8s = [ dev: [ clusterUrl: ‘k8s.cluster.notlocal’, credentialsId: ‘notlocal-credentials’ ] ] }
  • 22. JCasC unclassified: globalLibraries: libraries: - defaultVersion: "master" includeInChangesets: false name: "jsl" jenkins: clouds: - kubernetes: containerCapStr: "10" jenkinsTunnel: "jenkins-agent:50000" jenkinsUrl: "http://jenkins:8080" name: "kubernetes" jenkins: systemMessage: "Jenkins configured as Code”
  • 23. • Standard component of the Jenkins project • Schema validation • Vault integration • JobDSL for jobs declaration • Dynamic config reload • Doesn’t support plugin installation JCasC
  • 24. Demo
  • 25. • Keep it easy to read and maintain • Use declarative pipelines • Keep pipeline logic in Jenkinsfile • Use shared library only if it’s really required • Write custom steps in vars, don’t forget .txt • Join methods by tool (log, helm, maven, etc) • Check plugins first • Cleanup everything as part of pipeline • Read documentation Conclusion
  • 26. • kubernetes • kubernetes-credentials-provider • pipeline-utility-steps • github-organization-folder • cloudbees-bitbucket-branch-source • bitbucket-filter-project-trait • job-dsl • blueocean • prometheus • timestamper • rebuild Useful plugins
  • 27. • https://jenkins.io/doc/pipeline/steps/ • https://jenkins.io/doc/book/pipeline/shared-libraries/ • https://github.com/griddynamics/mpl • https://jenkins.io/doc/book/pipeline/pipeline-best-practices/ • http://aimtheory.com/jenkins/pipeline/continuous-delivery/2018/10/01/jenkins-pipeline-global- shared-library-best-practices-part-2.html • https://bmuschko.com/blog/jenkins-shared-libraries/ • https://medium.com/@werne2j/unit-testing-a-jenkins-shared-library-9bfb6b599748 https://github.com/jenkinsci/configuration-as-code-plugin • https://github.com/jenkinsci/configuration-as-code-plugin/tree/master/demos • https://github.com/vdksystem/techtalkjenkins-jsl • https://github.com/vdksystem/techtalkjenkins Links