SlideShare a Scribd company logo
Jenkin’s shared libraries in action
by Ed Yablonsky
● Simple examples
● Issues we meet
● Solutions we made
● Code
You will see
Monolith to Microservices
Continuous Integration
Continuous Deployment
We do
AWS, Kubernetes, Helm
Linkerd, Prometheus, Grafana
.Net Core, C#, Python, JavaScript, NodeJS
MySQL, Amazon Aurora, Redis
GitHub, Jenkins, Nexus
We use
● Script publishes service’s image ~300 lines
● Script deploys service ~250 lines
● Each service main script ~100 lines
● Inlined shell complex scripts
● Many parameters ~30
● Change script for each service
Problems
● Is an automated expression of your process for
getting software from version control to your
customers
● Declarative
● Scripted
Jenkins Pipeline
● Is a text file that contains the definition of a
Jenkins Pipeline and is checked into source
control
● Self-documented, versioned
● Single definition of build steps
● Make pipeline extendable
Jenkinsfile
pipeline {
agent any
stages {
stage('run') {
steps {
sh 'env'
}
}
}
}
Simple declarative pipeline
podTemplate {
node {
stage('run') {
sh 'env'
}
}
}
Simple scripted pipeline uses k8s plug-in
Demo
simple pipeline
Create new pipeline 1 - 2 - 3
Create new pipeline 1 - 2 - 3
Create new pipeline 1 - 2 - 3
Run pipeline
Use Jenkinsfile
Demo
dotnet pipeline
podTemplate {
node {
stage('checkout') {
git url: 'https://github.com/eDyablo/demo-dotnet.git'
}
stage('test') {
sh 'dotnet test Demo.Test'
}
}
}
Nice Jenkinsfile
def podLabel = "worker-${UUID.randomUUID()}"
podTemplate(
label: podLabel,
containers: [
containerTemplate(
name: 'dotnet',
image: 'microsoft/dotnet',
ttyEnabled: true,
command: 'cat')
]) {
node(podLabel) {
stage('checkout') {
git url: 'https://github.com/eDyablo/demo-dotnet.git'
}
stage('test') {
container('dotnet') {
sh 'dotnet test Demo.Test'
}
}
}
}
Jenkinsfile
1. Create new Git repository
2. Create file vars/dotnetTemplate.groovy
Do following
def call(String podLabel, code) {
podTemplate(
cloud: 'kubernetes-dev',
namespace: 'jenkins',
label: podLabel,
containers: [
containerTemplate(
name: 'dotnet',
image: 'microsoft/dotnet',
ttyEnabled: true,
command: 'cat')
]) {
code()
}
}
vars / dotnetTemplate.groovy
1. Create new Git repository
2. Create file vars/dotnetTemplate.groovy
3. Add repository reference as pipeline library
a. Set it “Load implicitly”
4. Modify pipeline script
Do following
Refer shared library
def podLabel = "worker-${UUID.randomUUID()}"
dotnetTemplate(podLabel) {
node(podLabel) {
stage('checkout') {
git url: 'https://github.com/eDyablo/demo-dotnet.git'
}
stage('test') {
container('dotnet') {
sh 'dotnet test Demo.Test'
}
}
}
}
Jenkinsfile
(root)
+- vars
| +- dotnetTemplate.groovy
| +- dotnetTemplate.txt
|
+- src
|
+- resources
Shared library directory structure
• Global
• Folder-level
• Dynamically loaded
Shared libraries can be
@Library('demo-shared@branch') _
def podLabel = "worker-${UUID.randomUUID()}"
dotnetTemplate(podLabel) {
node(podLabel) {
stage('checkout') {
git url: 'https://github.com/eDyablo/demo-dotnet.git'
}
stage('test') {
container('dotnet') {
sh 'dotnet test Demo.Test'
}
}
}
}
Jenkinsfile
Demo
parameterized pipeline
complex shell script
library resources
properties([
parameters([
string(name: 'REPOSITORY', defaultValue: 'edyablo/demo-dotnet', descrip
string(name: 'TEST_PROJECT', defaultValue: 'Demo.Test', description: 'N
choice(name: 'CONFIGURATION', defaultValue: 'Debug', choices: ['Debug',
])
])
dotnetTemplate(podLabel) {
node(podLabel) {
stage('checkout') {
git url: "https://github.com/${params.REPOSITORY}.git"
}
stage('test') {
container('dotnet') {
sh "dotnet test ./${params.TEST_PROJECT} --configuration ${params.C
}
}
}
}
Parameterized pipeline
Parameterized pipeline
properties([
parameters([
string(name: 'REPOSITORY', defaultValue: 'edyablo/demo-dotnet', description: 'Name
choice(name: 'CONFIGURATION', defaultValue: 'Debug', choices: ['Debug', 'Release']
])
])
dotnetTemplate(podLabel) {
node(podLabel) {
stage('checkout') {
git url: "https://github.com/${params.REPOSITORY}.git"
}
stage('test') {
container('dotnet') {
sh """
projects=`find . -regex '.*.Test.csproj'`
for project in $projects
do
dotnet test $project --configuration ${params.CONFIGURATION}
done
"""
}
More complex shell script
projects=`find . -regex '.*.Test.csproj'`
for project in $projects
do
dotnet test $project --configuration $CONFIGURATION
done
resources / dotnet-test.sh
properties([
parameters([
string(name: 'REPOSITORY', defaultValue: 'edyablo/demo-dotnet', descri
choice(name: 'CONFIGURATION', defaultValue: 'Debug', choices: ['Debug'
])
])
dotnetTemplate(podLabel) {
node(podLabel) {
stage('checkout') {
git url: "https://github.com/${params.REPOSITORY}.git"
}
stage('test') {
container('dotnet') {
sh(libraryResource('dotnet-test.sh'))
}
}
}
}
More complex shell script
properties([
parameters([
string(name: 'REPOSITORY', defaultValue: 'edyablo/demo-dotnet', descri
choice(name: 'BUILD_CONFIGURATION', defaultValue: 'Debug', choices: ['
])
])
dotnetTemplate(podLabel) {
node(podLabel) {
stage('checkout') {
git url: "https://github.com/${params.REPOSITORY}.git"
}
stage('test') {
container('dotnet') {
withEnv(["CONFIGURATION=$params.BUILD_CONFIGURATION"]) {
sh(libraryResource('dotnet-test.sh'))
}
}
}
}
More complex shell script
● Script’s overgrowth
● Complex shell scripts
● Escape character
● Code duplication
● Parameters
Issues
● Script’s overgrowth Use vars
● Complex shell scripts Use resources
● Escape character Use resources
● Code duplication Use vars,
resources, classes
● Parameters Use classes
Solution Use
shared library
Components
pipeline
kubectl
docker
dotnet
nexus
mysql
Tools
kubectl docker dotnet nexus
tool
Tool
DotnetConfig
defineParameters
loadParameters
defineEnvVars
DotnetClient
setup
buid
test
build.sh
test.sh
Demo
real code
package com.lohika.dotnet
import com.lohika.build.SecretReference
class DotnetConfig {
def nugetConfigRef
def defineParameters(pipeline) {
[ pipeline.string(name: 'DOTNET_NUGET_CONFIG_REF',
defaultValue: "$nugetConfigRef",
description: 'Reference to secret contains configuration for nuget package man
}
def loadParameters(params) {
nugetConfigRef = SecretReference.fromText(
params.DOTNET_NUGET_CONFIG_REF)
}
def defineEnvVars(pipeline) {
[ pipeline.secretEnvVar(key: 'NUGET_CONFIG',
secretName: nugetConfigRef.name, secretKey: nugetConfigRef.key) ]
}
src / com / lohika / dotnet / DotnetConfig.groovy
package com.lohika.dotnet
import com.lohika.shell.ShellClient
class DotnetClient extends ShellClient {
DotnetConfig config
def setup(pipeline) {
pipeline.sh('echo $NUGET_CONFIG > nuget.config')
}
def build(Map kwargs) {
def include = kwargs.include ?: ''
def exclude = kwargs.exclude ?: ''
def configuration = kwargs.configuration ?: 'Debug'
pipeline.withEnv(["BASE_DIR=$kwargs.baseDir",
"INCLUDE_PATTERN=${encodeForShell(include)}",
"EXCLUDE_PATTERN=${encodeForShell(exclude)}",
"BUILD_CONFIGURATION=$configuration"]) {
execute(pipeline.libraryResource(
'com/lohika/dotnet/dotnet-client-build.sh'))
}
}
src / com / lohika / dotnet / DotnetClient.groovy
baseDir=`realpath $BASE_DIR`
projects=`find "$baseDir" -regex "$INCLUDE_PATTERN" 
-and -not -regex "$EXCLUDE_PATTERN"`
for project in $projects
do
projectDir=`dirname $project`
dotnet restore "$projectDir" --configfile "$baseDir/nuget.config"
dotnet build "$project" --no-restore 
${BUILD_CONFIGURATION:+ --configuration "$BUILD_CONFIGURATION"}
done
resources/com/lohika/dotnet/dotnet-client-build.sh
Use DotnetClient
dotnetClient.build(
baseDir: '.',
include: /.*.csproj/,
configuration: 'Release')
dotnetClient.test(
baseDir: '.',
includeProjects: /.*.UnitTest.csproj/,
testFilter: 'Name~Ignore')
Job
PipelineJob
defineParameters
loadParameters
defineEnvVars
run
Tool
Tool
ToolConfig
Tool
Tool
ToolClient
Tool
scripts
runPipelineJob
import com.lohika.job.*
runPipelineJob(new PublishDotnetServiceJob(this)) {
dotnetConfig.nugetConfigRef = 'secrets : nuget.config'
gitConfig.baseUrl = 'https://github.com/demo'
gitConfig.branch = 'develop'
gitConfig.credsId = 'github-ci'
pipConfig.configRef = 'secrets : pip.config'
k8sConfig.configRef = 'secrets : kube.config'
service = 'demo-service'
}
Jenkinsfile
autoDeployServices {
services = [
'first : svc-first',
'second : svc-second : second-service',
'third'
]
nexus.baseUrl = 'artifacts.demo.com'
nexus.credsId = 'demo.nexus.ci'
k8s.configRef = 'secrets : kube.config : dev'
git.baseUrl = 'https://github.com/demo
git.branch = 'develop'
notify {
success {
slack url: '#demo.slack'
}
failure {
slack url: '#demo.slack'
}
}
}
Jenkinsfile
+- src
| +- com
| +- lohika
| +- dotnet
| +- DotnetConfig.groovy
| +- DotnetClient.groovy
+- resources
| +- com
| +- lohika
| +- dotnet
| +- dotnet-client-build.sh
| +- dotnet-client-test.sh
Directory structure
+- src
+- com
+- lohika
+- docker
+- dotnet
+- git
+- k8s
+- mysql
+- nexus
+- job
● Modularization
● Single responsibility
● Re-use
● Testability
Jenkins shared library
● Setup unit testing framework
● Use Groovy annotations
Next improvements
Thank You!

More Related Content

What's hot

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.
 
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
 
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.
 
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.
 
JavaOne 2016 - Pipeline as code
JavaOne 2016 - Pipeline as codeJavaOne 2016 - Pipeline as code
JavaOne 2016 - Pipeline as code
Bert Jan Schrijver
 
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
 
Container & kubernetes
Container & kubernetesContainer & kubernetes
Container & kubernetes
Ted Jung
 
Docker for Fun and Profit
Docker for Fun and ProfitDocker for Fun and Profit
Docker for Fun and Profit
Kel Cecil
 
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.
 
高レイテンシwebサーバのGKE構築と beta機能アレコレのハナシ
高レイテンシwebサーバのGKE構築と beta機能アレコレのハナシ高レイテンシwebサーバのGKE構築と beta機能アレコレのハナシ
高レイテンシwebサーバのGKE構築と beta機能アレコレのハナシ
Junpei Nomura
 
Jenkins & IaC
Jenkins & IaCJenkins & IaC
Jenkins & IaC
HungWei Chiu
 
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
 
Kubernetes Basic Operation
Kubernetes Basic OperationKubernetes Basic Operation
Kubernetes Basic Operation
Simon Su
 
Kubernetes Node Deep Dive
Kubernetes Node Deep DiveKubernetes Node Deep Dive
Kubernetes Node Deep Dive
Lei (Harry) Zhang
 
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
 
Scaling Development Environments with Docker
Scaling Development Environments with DockerScaling Development Environments with Docker
Scaling Development Environments with Docker
Docker, Inc.
 
Containerizing a Web Application with Vue.js and Java
Containerizing a Web Application with Vue.js and JavaContainerizing a Web Application with Vue.js and Java
Containerizing a Web Application with Vue.js and Java
Jadson Santos
 
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
 
Monitoring, Logging and Tracing on Kubernetes
Monitoring, Logging and Tracing on KubernetesMonitoring, Logging and Tracing on Kubernetes
Monitoring, Logging and Tracing on Kubernetes
Martin Etmajer
 
Kubernetes #4 volume & stateful set
Kubernetes #4   volume & stateful setKubernetes #4   volume & stateful set
Kubernetes #4 volume & stateful set
Terry Cho
 

What's hot (20)

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
 
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
 
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
 
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
 
JavaOne 2016 - Pipeline as code
JavaOne 2016 - Pipeline as codeJavaOne 2016 - Pipeline as code
JavaOne 2016 - Pipeline as code
 
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
 
Container & kubernetes
Container & kubernetesContainer & kubernetes
Container & kubernetes
 
Docker for Fun and Profit
Docker for Fun and ProfitDocker for Fun and Profit
Docker for Fun and Profit
 
Container Orchestration from Theory to Practice
Container Orchestration from Theory to PracticeContainer Orchestration from Theory to Practice
Container Orchestration from Theory to Practice
 
高レイテンシwebサーバのGKE構築と beta機能アレコレのハナシ
高レイテンシwebサーバのGKE構築と beta機能アレコレのハナシ高レイテンシwebサーバのGKE構築と beta機能アレコレのハナシ
高レイテンシwebサーバのGKE構築と beta機能アレコレのハナシ
 
Jenkins & IaC
Jenkins & IaCJenkins & IaC
Jenkins & IaC
 
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
 
Kubernetes Basic Operation
Kubernetes Basic OperationKubernetes Basic Operation
Kubernetes Basic Operation
 
Kubernetes Node Deep Dive
Kubernetes Node Deep DiveKubernetes Node Deep Dive
Kubernetes Node Deep Dive
 
Docker for Developers - php[tek] 2017
Docker for Developers - php[tek] 2017Docker for Developers - php[tek] 2017
Docker for Developers - php[tek] 2017
 
Scaling Development Environments with Docker
Scaling Development Environments with DockerScaling Development Environments with Docker
Scaling Development Environments with Docker
 
Containerizing a Web Application with Vue.js and Java
Containerizing a Web Application with Vue.js and JavaContainerizing a Web Application with Vue.js and Java
Containerizing a Web Application with Vue.js and Java
 
Observability in a Dynamically Scheduled World
Observability in a Dynamically Scheduled WorldObservability in a Dynamically Scheduled World
Observability in a Dynamically Scheduled World
 
Monitoring, Logging and Tracing on Kubernetes
Monitoring, Logging and Tracing on KubernetesMonitoring, Logging and Tracing on Kubernetes
Monitoring, Logging and Tracing on Kubernetes
 
Kubernetes #4 volume & stateful set
Kubernetes #4   volume & stateful setKubernetes #4   volume & stateful set
Kubernetes #4 volume & stateful set
 

Similar to Jenkins' shared libraries in action

GradleFX
GradleFXGradleFX
Excelian hyperledger walkthrough-feb17
Excelian hyperledger walkthrough-feb17Excelian hyperledger walkthrough-feb17
Excelian hyperledger walkthrough-feb17
Excelian | Luxoft Financial Services
 
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
 
Jenkins Pipelines
Jenkins PipelinesJenkins Pipelines
Jenkins Pipelines
Steffen Gebert
 
Continuous Integration With Jenkins Docker SQL Server
Continuous Integration With Jenkins Docker SQL ServerContinuous Integration With Jenkins Docker SQL Server
Continuous Integration With Jenkins Docker SQL Server
Chris Adkin
 
Practical introduction to dev ops with chef
Practical introduction to dev ops with chefPractical introduction to dev ops with chef
Practical introduction to dev ops with chefLeanDog
 
Deploying windows containers with kubernetes
Deploying windows containers with kubernetesDeploying windows containers with kubernetes
Deploying windows containers with kubernetes
Ben Hall
 
(Declarative) Jenkins Pipelines
(Declarative) Jenkins Pipelines(Declarative) Jenkins Pipelines
(Declarative) Jenkins Pipelines
Steffen Gebert
 
Kubernetes - training micro-dragons without getting burnt
Kubernetes -  training micro-dragons without getting burntKubernetes -  training micro-dragons without getting burnt
Kubernetes - training micro-dragons without getting burnt
Amir Moghimi
 
Introduction of Docker and Docker Compose
Introduction of Docker and Docker ComposeIntroduction of Docker and Docker Compose
Introduction of Docker and Docker Compose
Dr. Ketan Parmar
 
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
 
Test Automation for NoSQL Databases
Test Automation for NoSQL DatabasesTest Automation for NoSQL Databases
Test Automation for NoSQL Databases
Tobias Trelle
 
DevOPS training - Day 2/2
DevOPS training - Day 2/2DevOPS training - Day 2/2
DevOPS training - Day 2/2
Vincent Mercier
 
Antons Kranga Building Agile Infrastructures
Antons Kranga   Building Agile InfrastructuresAntons Kranga   Building Agile Infrastructures
Antons Kranga Building Agile Infrastructures
Antons Kranga
 
Dev ops meetup
Dev ops meetupDev ops meetup
Dev ops meetup
Bigdata Meetup Kochi
 
The Fairy Tale of the One Command Build Script
The Fairy Tale of the One Command Build ScriptThe Fairy Tale of the One Command Build Script
The Fairy Tale of the One Command Build Script
Docker, Inc.
 
Powercoders · Docker · Fall 2021.pptx
Powercoders · Docker · Fall 2021.pptxPowercoders · Docker · Fall 2021.pptx
Powercoders · Docker · Fall 2021.pptx
IgnacioTamayo2
 
Bangpypers april-meetup-2012
Bangpypers april-meetup-2012Bangpypers april-meetup-2012
Bangpypers april-meetup-2012
Deepak Garg
 
Kubernetes Basis: Pods, Deployments, and Services
Kubernetes Basis: Pods, Deployments, and ServicesKubernetes Basis: Pods, Deployments, and Services
Kubernetes Basis: Pods, Deployments, and Services
Jian-Kai Wang
 
Architecting .NET solutions in a Docker ecosystem - .NET Fest Kyiv 2019
Architecting .NET solutions in a Docker ecosystem - .NET Fest Kyiv 2019Architecting .NET solutions in a Docker ecosystem - .NET Fest Kyiv 2019
Architecting .NET solutions in a Docker ecosystem - .NET Fest Kyiv 2019
Alex Thissen
 

Similar to Jenkins' shared libraries in action (20)

GradleFX
GradleFXGradleFX
GradleFX
 
Excelian hyperledger walkthrough-feb17
Excelian hyperledger walkthrough-feb17Excelian hyperledger walkthrough-feb17
Excelian hyperledger walkthrough-feb17
 
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
 
Jenkins Pipelines
Jenkins PipelinesJenkins Pipelines
Jenkins Pipelines
 
Continuous Integration With Jenkins Docker SQL Server
Continuous Integration With Jenkins Docker SQL ServerContinuous Integration With Jenkins Docker SQL Server
Continuous Integration With Jenkins Docker SQL Server
 
Practical introduction to dev ops with chef
Practical introduction to dev ops with chefPractical introduction to dev ops with chef
Practical introduction to dev ops with chef
 
Deploying windows containers with kubernetes
Deploying windows containers with kubernetesDeploying windows containers with kubernetes
Deploying windows containers with kubernetes
 
(Declarative) Jenkins Pipelines
(Declarative) Jenkins Pipelines(Declarative) Jenkins Pipelines
(Declarative) Jenkins Pipelines
 
Kubernetes - training micro-dragons without getting burnt
Kubernetes -  training micro-dragons without getting burntKubernetes -  training micro-dragons without getting burnt
Kubernetes - training micro-dragons without getting burnt
 
Introduction of Docker and Docker Compose
Introduction of Docker and Docker ComposeIntroduction of Docker and Docker Compose
Introduction of Docker and Docker Compose
 
Integration tests: use the containers, Luke!
Integration tests: use the containers, Luke!Integration tests: use the containers, Luke!
Integration tests: use the containers, Luke!
 
Test Automation for NoSQL Databases
Test Automation for NoSQL DatabasesTest Automation for NoSQL Databases
Test Automation for NoSQL Databases
 
DevOPS training - Day 2/2
DevOPS training - Day 2/2DevOPS training - Day 2/2
DevOPS training - Day 2/2
 
Antons Kranga Building Agile Infrastructures
Antons Kranga   Building Agile InfrastructuresAntons Kranga   Building Agile Infrastructures
Antons Kranga Building Agile Infrastructures
 
Dev ops meetup
Dev ops meetupDev ops meetup
Dev ops meetup
 
The Fairy Tale of the One Command Build Script
The Fairy Tale of the One Command Build ScriptThe Fairy Tale of the One Command Build Script
The Fairy Tale of the One Command Build Script
 
Powercoders · Docker · Fall 2021.pptx
Powercoders · Docker · Fall 2021.pptxPowercoders · Docker · Fall 2021.pptx
Powercoders · Docker · Fall 2021.pptx
 
Bangpypers april-meetup-2012
Bangpypers april-meetup-2012Bangpypers april-meetup-2012
Bangpypers april-meetup-2012
 
Kubernetes Basis: Pods, Deployments, and Services
Kubernetes Basis: Pods, Deployments, and ServicesKubernetes Basis: Pods, Deployments, and Services
Kubernetes Basis: Pods, Deployments, and Services
 
Architecting .NET solutions in a Docker ecosystem - .NET Fest Kyiv 2019
Architecting .NET solutions in a Docker ecosystem - .NET Fest Kyiv 2019Architecting .NET solutions in a Docker ecosystem - .NET Fest Kyiv 2019
Architecting .NET solutions in a Docker ecosystem - .NET Fest Kyiv 2019
 

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

H.Seo, ICLR 2024, MLILAB, KAIST AI.pdf
H.Seo,  ICLR 2024, MLILAB,  KAIST AI.pdfH.Seo,  ICLR 2024, MLILAB,  KAIST AI.pdf
H.Seo, ICLR 2024, MLILAB, KAIST AI.pdf
MLILAB
 
J.Yang, ICLR 2024, MLILAB, KAIST AI.pdf
J.Yang,  ICLR 2024, MLILAB, KAIST AI.pdfJ.Yang,  ICLR 2024, MLILAB, KAIST AI.pdf
J.Yang, ICLR 2024, MLILAB, KAIST AI.pdf
MLILAB
 
weather web application report.pdf
weather web application report.pdfweather web application report.pdf
weather web application report.pdf
Pratik Pawar
 
Final project report on grocery store management system..pdf
Final project report on grocery store management system..pdfFinal project report on grocery store management system..pdf
Final project report on grocery store management system..pdf
Kamal Acharya
 
The Benefits and Techniques of Trenchless Pipe Repair.pdf
The Benefits and Techniques of Trenchless Pipe Repair.pdfThe Benefits and Techniques of Trenchless Pipe Repair.pdf
The Benefits and Techniques of Trenchless Pipe Repair.pdf
Pipe Restoration Solutions
 
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&BDesign and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Sreedhar Chowdam
 
ASME IX(9) 2007 Full Version .pdf
ASME IX(9)  2007 Full Version       .pdfASME IX(9)  2007 Full Version       .pdf
ASME IX(9) 2007 Full Version .pdf
AhmedHussein950959
 
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdfAKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
SamSarthak3
 
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
AJAYKUMARPUND1
 
Event Management System Vb Net Project Report.pdf
Event Management System Vb Net  Project Report.pdfEvent Management System Vb Net  Project Report.pdf
Event Management System Vb Net Project Report.pdf
Kamal Acharya
 
Vaccine management system project report documentation..pdf
Vaccine management system project report documentation..pdfVaccine management system project report documentation..pdf
Vaccine management system project report documentation..pdf
Kamal Acharya
 
COLLEGE BUS MANAGEMENT SYSTEM PROJECT REPORT.pdf
COLLEGE BUS MANAGEMENT SYSTEM PROJECT REPORT.pdfCOLLEGE BUS MANAGEMENT SYSTEM PROJECT REPORT.pdf
COLLEGE BUS MANAGEMENT SYSTEM PROJECT REPORT.pdf
Kamal Acharya
 
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
obonagu
 
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
Dr.Costas Sachpazis
 
ethical hacking-mobile hacking methods.ppt
ethical hacking-mobile hacking methods.pptethical hacking-mobile hacking methods.ppt
ethical hacking-mobile hacking methods.ppt
Jayaprasanna4
 
Water Industry Process Automation and Control Monthly - May 2024.pdf
Water Industry Process Automation and Control Monthly - May 2024.pdfWater Industry Process Automation and Control Monthly - May 2024.pdf
Water Industry Process Automation and Control Monthly - May 2024.pdf
Water Industry Process Automation & Control
 
CME397 Surface Engineering- Professional Elective
CME397 Surface Engineering- Professional ElectiveCME397 Surface Engineering- Professional Elective
CME397 Surface Engineering- Professional Elective
karthi keyan
 
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
MdTanvirMahtab2
 
block diagram and signal flow graph representation
block diagram and signal flow graph representationblock diagram and signal flow graph representation
block diagram and signal flow graph representation
Divya Somashekar
 
addressing modes in computer architecture
addressing modes  in computer architectureaddressing modes  in computer architecture
addressing modes in computer architecture
ShahidSultan24
 

Recently uploaded (20)

H.Seo, ICLR 2024, MLILAB, KAIST AI.pdf
H.Seo,  ICLR 2024, MLILAB,  KAIST AI.pdfH.Seo,  ICLR 2024, MLILAB,  KAIST AI.pdf
H.Seo, ICLR 2024, MLILAB, KAIST AI.pdf
 
J.Yang, ICLR 2024, MLILAB, KAIST AI.pdf
J.Yang,  ICLR 2024, MLILAB, KAIST AI.pdfJ.Yang,  ICLR 2024, MLILAB, KAIST AI.pdf
J.Yang, ICLR 2024, MLILAB, KAIST AI.pdf
 
weather web application report.pdf
weather web application report.pdfweather web application report.pdf
weather web application report.pdf
 
Final project report on grocery store management system..pdf
Final project report on grocery store management system..pdfFinal project report on grocery store management system..pdf
Final project report on grocery store management system..pdf
 
The Benefits and Techniques of Trenchless Pipe Repair.pdf
The Benefits and Techniques of Trenchless Pipe Repair.pdfThe Benefits and Techniques of Trenchless Pipe Repair.pdf
The Benefits and Techniques of Trenchless Pipe Repair.pdf
 
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&BDesign and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
 
ASME IX(9) 2007 Full Version .pdf
ASME IX(9)  2007 Full Version       .pdfASME IX(9)  2007 Full Version       .pdf
ASME IX(9) 2007 Full Version .pdf
 
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdfAKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
 
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
 
Event Management System Vb Net Project Report.pdf
Event Management System Vb Net  Project Report.pdfEvent Management System Vb Net  Project Report.pdf
Event Management System Vb Net Project Report.pdf
 
Vaccine management system project report documentation..pdf
Vaccine management system project report documentation..pdfVaccine management system project report documentation..pdf
Vaccine management system project report documentation..pdf
 
COLLEGE BUS MANAGEMENT SYSTEM PROJECT REPORT.pdf
COLLEGE BUS MANAGEMENT SYSTEM PROJECT REPORT.pdfCOLLEGE BUS MANAGEMENT SYSTEM PROJECT REPORT.pdf
COLLEGE BUS MANAGEMENT SYSTEM PROJECT REPORT.pdf
 
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
 
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
 
ethical hacking-mobile hacking methods.ppt
ethical hacking-mobile hacking methods.pptethical hacking-mobile hacking methods.ppt
ethical hacking-mobile hacking methods.ppt
 
Water Industry Process Automation and Control Monthly - May 2024.pdf
Water Industry Process Automation and Control Monthly - May 2024.pdfWater Industry Process Automation and Control Monthly - May 2024.pdf
Water Industry Process Automation and Control Monthly - May 2024.pdf
 
CME397 Surface Engineering- Professional Elective
CME397 Surface Engineering- Professional ElectiveCME397 Surface Engineering- Professional Elective
CME397 Surface Engineering- Professional Elective
 
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
 
block diagram and signal flow graph representation
block diagram and signal flow graph representationblock diagram and signal flow graph representation
block diagram and signal flow graph representation
 
addressing modes in computer architecture
addressing modes  in computer architectureaddressing modes  in computer architecture
addressing modes in computer architecture
 

Jenkins' shared libraries in action

  • 1. Jenkin’s shared libraries in action by Ed Yablonsky
  • 2. ● Simple examples ● Issues we meet ● Solutions we made ● Code You will see
  • 3. Monolith to Microservices Continuous Integration Continuous Deployment We do
  • 4. AWS, Kubernetes, Helm Linkerd, Prometheus, Grafana .Net Core, C#, Python, JavaScript, NodeJS MySQL, Amazon Aurora, Redis GitHub, Jenkins, Nexus We use
  • 5. ● Script publishes service’s image ~300 lines ● Script deploys service ~250 lines ● Each service main script ~100 lines ● Inlined shell complex scripts ● Many parameters ~30 ● Change script for each service Problems
  • 6. ● Is an automated expression of your process for getting software from version control to your customers ● Declarative ● Scripted Jenkins Pipeline
  • 7. ● Is a text file that contains the definition of a Jenkins Pipeline and is checked into source control ● Self-documented, versioned ● Single definition of build steps ● Make pipeline extendable Jenkinsfile
  • 8. pipeline { agent any stages { stage('run') { steps { sh 'env' } } } } Simple declarative pipeline
  • 9. podTemplate { node { stage('run') { sh 'env' } } } Simple scripted pipeline uses k8s plug-in
  • 11. Create new pipeline 1 - 2 - 3
  • 12. Create new pipeline 1 - 2 - 3
  • 13. Create new pipeline 1 - 2 - 3
  • 17. podTemplate { node { stage('checkout') { git url: 'https://github.com/eDyablo/demo-dotnet.git' } stage('test') { sh 'dotnet test Demo.Test' } } } Nice Jenkinsfile
  • 18. def podLabel = "worker-${UUID.randomUUID()}" podTemplate( label: podLabel, containers: [ containerTemplate( name: 'dotnet', image: 'microsoft/dotnet', ttyEnabled: true, command: 'cat') ]) { node(podLabel) { stage('checkout') { git url: 'https://github.com/eDyablo/demo-dotnet.git' } stage('test') { container('dotnet') { sh 'dotnet test Demo.Test' } } } } Jenkinsfile
  • 19. 1. Create new Git repository 2. Create file vars/dotnetTemplate.groovy Do following
  • 20. def call(String podLabel, code) { podTemplate( cloud: 'kubernetes-dev', namespace: 'jenkins', label: podLabel, containers: [ containerTemplate( name: 'dotnet', image: 'microsoft/dotnet', ttyEnabled: true, command: 'cat') ]) { code() } } vars / dotnetTemplate.groovy
  • 21. 1. Create new Git repository 2. Create file vars/dotnetTemplate.groovy 3. Add repository reference as pipeline library a. Set it “Load implicitly” 4. Modify pipeline script Do following
  • 23. def podLabel = "worker-${UUID.randomUUID()}" dotnetTemplate(podLabel) { node(podLabel) { stage('checkout') { git url: 'https://github.com/eDyablo/demo-dotnet.git' } stage('test') { container('dotnet') { sh 'dotnet test Demo.Test' } } } } Jenkinsfile
  • 24. (root) +- vars | +- dotnetTemplate.groovy | +- dotnetTemplate.txt | +- src | +- resources Shared library directory structure
  • 25. • Global • Folder-level • Dynamically loaded Shared libraries can be
  • 26. @Library('demo-shared@branch') _ def podLabel = "worker-${UUID.randomUUID()}" dotnetTemplate(podLabel) { node(podLabel) { stage('checkout') { git url: 'https://github.com/eDyablo/demo-dotnet.git' } stage('test') { container('dotnet') { sh 'dotnet test Demo.Test' } } } } Jenkinsfile
  • 27. Demo parameterized pipeline complex shell script library resources
  • 28. properties([ parameters([ string(name: 'REPOSITORY', defaultValue: 'edyablo/demo-dotnet', descrip string(name: 'TEST_PROJECT', defaultValue: 'Demo.Test', description: 'N choice(name: 'CONFIGURATION', defaultValue: 'Debug', choices: ['Debug', ]) ]) dotnetTemplate(podLabel) { node(podLabel) { stage('checkout') { git url: "https://github.com/${params.REPOSITORY}.git" } stage('test') { container('dotnet') { sh "dotnet test ./${params.TEST_PROJECT} --configuration ${params.C } } } } Parameterized pipeline
  • 30. properties([ parameters([ string(name: 'REPOSITORY', defaultValue: 'edyablo/demo-dotnet', description: 'Name choice(name: 'CONFIGURATION', defaultValue: 'Debug', choices: ['Debug', 'Release'] ]) ]) dotnetTemplate(podLabel) { node(podLabel) { stage('checkout') { git url: "https://github.com/${params.REPOSITORY}.git" } stage('test') { container('dotnet') { sh """ projects=`find . -regex '.*.Test.csproj'` for project in $projects do dotnet test $project --configuration ${params.CONFIGURATION} done """ } More complex shell script
  • 31. projects=`find . -regex '.*.Test.csproj'` for project in $projects do dotnet test $project --configuration $CONFIGURATION done resources / dotnet-test.sh
  • 32. properties([ parameters([ string(name: 'REPOSITORY', defaultValue: 'edyablo/demo-dotnet', descri choice(name: 'CONFIGURATION', defaultValue: 'Debug', choices: ['Debug' ]) ]) dotnetTemplate(podLabel) { node(podLabel) { stage('checkout') { git url: "https://github.com/${params.REPOSITORY}.git" } stage('test') { container('dotnet') { sh(libraryResource('dotnet-test.sh')) } } } } More complex shell script
  • 33. properties([ parameters([ string(name: 'REPOSITORY', defaultValue: 'edyablo/demo-dotnet', descri choice(name: 'BUILD_CONFIGURATION', defaultValue: 'Debug', choices: [' ]) ]) dotnetTemplate(podLabel) { node(podLabel) { stage('checkout') { git url: "https://github.com/${params.REPOSITORY}.git" } stage('test') { container('dotnet') { withEnv(["CONFIGURATION=$params.BUILD_CONFIGURATION"]) { sh(libraryResource('dotnet-test.sh')) } } } } More complex shell script
  • 34. ● Script’s overgrowth ● Complex shell scripts ● Escape character ● Code duplication ● Parameters Issues
  • 35. ● Script’s overgrowth Use vars ● Complex shell scripts Use resources ● Escape character Use resources ● Code duplication Use vars, resources, classes ● Parameters Use classes Solution Use shared library
  • 40. package com.lohika.dotnet import com.lohika.build.SecretReference class DotnetConfig { def nugetConfigRef def defineParameters(pipeline) { [ pipeline.string(name: 'DOTNET_NUGET_CONFIG_REF', defaultValue: "$nugetConfigRef", description: 'Reference to secret contains configuration for nuget package man } def loadParameters(params) { nugetConfigRef = SecretReference.fromText( params.DOTNET_NUGET_CONFIG_REF) } def defineEnvVars(pipeline) { [ pipeline.secretEnvVar(key: 'NUGET_CONFIG', secretName: nugetConfigRef.name, secretKey: nugetConfigRef.key) ] } src / com / lohika / dotnet / DotnetConfig.groovy
  • 41. package com.lohika.dotnet import com.lohika.shell.ShellClient class DotnetClient extends ShellClient { DotnetConfig config def setup(pipeline) { pipeline.sh('echo $NUGET_CONFIG > nuget.config') } def build(Map kwargs) { def include = kwargs.include ?: '' def exclude = kwargs.exclude ?: '' def configuration = kwargs.configuration ?: 'Debug' pipeline.withEnv(["BASE_DIR=$kwargs.baseDir", "INCLUDE_PATTERN=${encodeForShell(include)}", "EXCLUDE_PATTERN=${encodeForShell(exclude)}", "BUILD_CONFIGURATION=$configuration"]) { execute(pipeline.libraryResource( 'com/lohika/dotnet/dotnet-client-build.sh')) } } src / com / lohika / dotnet / DotnetClient.groovy
  • 42. baseDir=`realpath $BASE_DIR` projects=`find "$baseDir" -regex "$INCLUDE_PATTERN" -and -not -regex "$EXCLUDE_PATTERN"` for project in $projects do projectDir=`dirname $project` dotnet restore "$projectDir" --configfile "$baseDir/nuget.config" dotnet build "$project" --no-restore ${BUILD_CONFIGURATION:+ --configuration "$BUILD_CONFIGURATION"} done resources/com/lohika/dotnet/dotnet-client-build.sh
  • 43. Use DotnetClient dotnetClient.build( baseDir: '.', include: /.*.csproj/, configuration: 'Release') dotnetClient.test( baseDir: '.', includeProjects: /.*.UnitTest.csproj/, testFilter: 'Name~Ignore')
  • 45. import com.lohika.job.* runPipelineJob(new PublishDotnetServiceJob(this)) { dotnetConfig.nugetConfigRef = 'secrets : nuget.config' gitConfig.baseUrl = 'https://github.com/demo' gitConfig.branch = 'develop' gitConfig.credsId = 'github-ci' pipConfig.configRef = 'secrets : pip.config' k8sConfig.configRef = 'secrets : kube.config' service = 'demo-service' } Jenkinsfile
  • 46. autoDeployServices { services = [ 'first : svc-first', 'second : svc-second : second-service', 'third' ] nexus.baseUrl = 'artifacts.demo.com' nexus.credsId = 'demo.nexus.ci' k8s.configRef = 'secrets : kube.config : dev' git.baseUrl = 'https://github.com/demo git.branch = 'develop' notify { success { slack url: '#demo.slack' } failure { slack url: '#demo.slack' } } } Jenkinsfile
  • 47. +- src | +- com | +- lohika | +- dotnet | +- DotnetConfig.groovy | +- DotnetClient.groovy +- resources | +- com | +- lohika | +- dotnet | +- dotnet-client-build.sh | +- dotnet-client-test.sh Directory structure +- src +- com +- lohika +- docker +- dotnet +- git +- k8s +- mysql +- nexus +- job
  • 48. ● Modularization ● Single responsibility ● Re-use ● Testability Jenkins shared library
  • 49. ● Setup unit testing framework ● Use Groovy annotations Next improvements