SlideShare a Scribd company logo
Jenkins multibranch pipeline workshop sep 2018
SoftServe Confidential
Oleksandr Metelytsia
ometel@softserveinc.com
metelitsa.alexandr@gmail.com
Yermek Kadyrbayev
ykad@softserveinc.com
kadyrbayev.yermek@gmail.com
SoftServe Confidential
Content
● CI
● Git branching
● Shift left
● Docker
● Workshop
SoftServe Confidential
What is this?
SoftServe Confidential
Jenkins multibranch pipeline workshop sep 2018
SoftServe Confidential
Why?
Jenkins multibranch pipeline workshop sep 2018
SoftServe Confidential
Shift left
SoftServe Confidential
SoftServe Confidential
Jenkins Blue Ocean
SoftServe Confidential
SoftServe Confidential
Docker
Docker 101
docker build
docker run
docker login
docker pull
docker images
docker ps
docker exec
docker network
Dockerfile
Image vs container
What is docker registry?
SoftServe Confidential
SoftServe Confidential
SoftServe Confidential
WiFi: SS-GUEST
Password: Welcome!
SoftServe Confidential
https://goo.gl/D5Ee3B
Link to presentation
SoftServe Confidential
Do not forget to
switch to
Linux Containers
For Windows 10
SoftServe Confidential
Start from pulling
The very first command, but it may take some time so do it right now:
$ mkdir workshop
$ cd workshop
$ pwd
$ docker login https://registry-1.docker.io
$ docker pull jenkinsci/blueocean
* if have unauthorised error, run following command:
Create working dir and cd to it:
SoftServe Confidential
Start Jenkins container
$ docker run 
--rm 
-u root 
-p 8080:8080 
-v jenkins-data:/var/jenkins_home 
-v /var/run/docker.sock:/var/run/docker.sock 
jenkinsci/blueocean
From “docker run --help”:
-v, --volume list Bind mount a volume
* For Win10 use ^ instead of
SoftServe Confidential
Setup Wizard
1. Go to http://localhost:8080
2. Unlock Jenkins with password which is in terminal
between two sets of asterisks
3. Click “Install suggested plugins”
4. Create First Admin User
5. Save and Finish
6. Start using Jenkins
SoftServe Confidential
Stop and restart Jenkins (if needed)
If something went “terribly wrong”:
1. Stop Jenkins by Ctrl+C in terminal
2. Run the same “docker run …​” command to restart
3. Wait till login page
4. Login back
If you want to debug container:
1. Add flag “--name jenkins-workshop” to “docker run …​” command
2. In separate terminal window run:
$ docker exec -it jenkins-workshop bash
SoftServe Confidential
Fork repo
https://bitbucket.org/AlexMetelitsa/
multibranch-pipeline-project
SoftServe Confidential
Fork repo with tests
SoftServe Confidential
Clone forked repo
$ git clone 
https://YOUR_BITBUCKET_USERNAME
@bitbucket.org/YOUR_BITBUCKET_USERNAME
/multibranch-pipeline-project.git
SoftServe Confidential
Create and push branches: dev and prod
$ cd multibranch-pipeline-project
$ git branch dev
$ git branch prod
$ git branch
dev
* master
prod
$ git push origin -u dev:dev
$ git push origin -u prod:prod
SoftServe Confidential
Create pipeline project in BlueOcean
1. Browse to http://localhost:8080/blue and log in
or browse to http://localhost:8080, login and click Open Blue Ocean on the left
2. Click on “Create a new Pipeline”
3. Where do you store your code: “Bitbucket Cloud”
4. Connect to bitbucket with your own bitbucket credentials and fork of the repo
SoftServe Confidential
Setup Scan Trigger
Open pipeline settings by clicking on Gear button and setup:
f
SoftServe Confidential
Let’s take a look on Jenkinsfile stub
$ cat Jenkinsfile
pipeline {
agent any
stages {
stage('Build') {
steps {
sh 'echo "Hello world!"'
}
}
}
}
SoftServe Confidential
Jenkins UI
SoftServe Confidential
Finally branching...
Now we want to start CI development on a branch.
$ git checkout dev
Add new stage to Jenkinsfile which will build web docker container:
$ cat Jenkinsfile
pipeline {
agent none
stages {
stage('Build web') {
agent {
dockerfile {
additionalBuildArgs '-t web'
}
}
steps {
sh 'echo web built'
}
}
}
}
SoftServe Confidential
View new stage on Jenkins UI
$ git commit -a -m "Add build web stage"
$ git push origin dev
SoftServe Confidential
Next stage: build test env container
Add to Jenkins file stage to build container with selenium, firefox, etc.
stage('Build Test Env') {
agent {
dockerfile {
dir 'tests'
additionalBuildArgs '-t test_env'
}
}
steps {
sh 'echo test env container was built'
}
}
SoftServe Confidential
Back to Jenkins UI
$ git commit -a -m "Add build test env stage"
$ git push origin dev
SoftServe Confidential
“General” stage: e.g. Create network
We can run any kind of bash scripts or commands. Let’s run ‘create_network.sh’.
stage('Create network') {
agent any
steps {
sh 'sh ./create_network.sh'
}
}
$ cat create_network.sh
#!/usr/bin/env sh
if docker network ls | grep net; then
echo "Network with net name was found. Skipping network creation."
else
docker network create net
fi
Add new stage to Jenkinsfile:
SoftServe Confidential
Jenkins UI
$ git commit -a -m "Add create network stage"
$ git push origin dev
SoftServe Confidential
Run Application locally
$ docker network ls | grep net > /dev/null || docker network create net
$ docker run --rm --network net -p 6379:6379 --name redis -d redis
$ docker run --rm --network net -p 80:80 --name web -d web
$ curl 127.0.0.1:80
<h3>Hello World!</h3><b>Visits:</b><b id='visits'>1</b><br/>
Go to in browser http://localhost:80
* for Win10 just run:
$ docker network create net
SoftServe Confidential
Run tests locally
$ docker ps
CONTAINER ID IMAGE COMMAND NAMES
572c2c78327f web "python app.py" web
c5fa2dbd7e05 redis "docker-entrypoint.s…" redis
3f8df588fc5e jenkinsci/blueocean "/sbin/tini -- /usr/…" blissful_nightingale
$ docker run --network net test_env
test_app (test.SeleniumTest) ... ok
----------------------------------------------------------------------
Ran 1 test in 2.734s
OK
$ docker kill web redis
SoftServe Confidential
Finally Test stage (yey)
stage('Test') {
agent any
steps {
sh 'docker run --rm --network net -p 6379:6379 --name redis -d redis'
sh 'echo Redis started!'
sh 'docker run --rm --network net -p 80:80 --name web -d web'
sh 'echo Web started!'
sh 'docker run --network net test_env'
}
post {
always {
sh 'docker kill web 2>/dev/null || true'
sh 'docker kill redis 2>/dev/null || true'
}
}
}
SoftServe Confidential
Jenkins UI
$ git commit -a -m "Add create Test stage"
$ git push origin dev
SoftServe Confidential
‘bad feature’ development
$ git checkout -b bad_feature
Edit app.py: change “Hello World!” to “Goodbye World!”.
$ git commit -a -m "New cool feature done"
$ git push origin bad_feature
Create pull request from bad_feature branch to dev branch.
Make sure you are doing PR against your Fork repo and not AlexMetelitsa repo.
SoftServe Confidential
New feature PR
SoftServe Confidential
See broken tests before PR merge
SoftServe Confidential
Add deploy to Dev and to Prod stages
$ git checkout dev
Add deploy stages:
stage('Deploy for Dev') {
agent any
when {
branch 'dev'
}
steps {
sh 'echo Deploying to dev...'
sh 'echo Deployed to Dev!'
}
}
stage('Deploy for Prod') {
agent any
when {
branch 'prod'
}
steps {
input message: 'Click proceed to continue'
sh 'echo Deploying to Prod...'
sh 'echo Deployed to Prod!'
}
}
SoftServe Confidential
View new stages on Jenkins UI
$ git commit -a -m "Add build web stage"
$ git push
SoftServe Confidential
Create PR and merge to prod
Create PR dev to prod and merge it:
SoftServe Confidential
Conclusion. Finally :)
SoftServe Confidential
Useful links
https://jenkins.io/doc/book/pipeline/syntax/
https://docs.docker.com/engine/reference/commandline/docker/
https://jenkins.io/doc/book/blueocean/
https://jenkins.io/doc/tutorials/build-a-multibranch-pipeline-project/
https://confluence.atlassian.com/bitbucket/pull-request-and-merge-settings-951411948.html
SoftServe Confidential
Questions?

More Related Content

PPTX
Building CI/CD Pipelines with Jenkins and Kubernetes
PDF
Introduction to DevOps Tools | DevOps Training | DevOps Tutorial for Beginner...
PPTX
GitLab for CI/CD process
PDF
Jenkins tutorial
PDF
Introduction to GitHub Actions
PPTX
Fundamentals of DevOps and CI/CD
PPTX
PPTX
Git Pull Requests
Building CI/CD Pipelines with Jenkins and Kubernetes
Introduction to DevOps Tools | DevOps Training | DevOps Tutorial for Beginner...
GitLab for CI/CD process
Jenkins tutorial
Introduction to GitHub Actions
Fundamentals of DevOps and CI/CD
Git Pull Requests

What's hot (20)

PPTX
Git and GitHub | Concept about Git and GitHub Process | Git Process overview
PDF
svn 능력자를 위한 git 개념 가이드
PDF
Gitlab flow solo
PDF
Using GitLab CI
PPTX
JUNit Presentation
PPTX
CI/CD with GitHub Actions
PPTX
Jenkins CI
PPTX
Why Aren't You Using Git Flow?
PDF
Gitlab ci, cncf.sk
PDF
MuleSoft Surat Meetup#42 - Runtime Fabric Manager on Self Managed Kubernetes ...
PPTX
Git Lab Introduction
KEY
Git and GitHub
PDF
Yale Jenkins Show and Tell
PDF
GITS Class #16: CI/CD (Continuous Integration & Continuous Deployment) with G...
PDF
Getting Started with Kubernetes
PDF
CI CD Pipeline Using Jenkins | Continuous Integration and Deployment | DevOps...
PDF
Gitlab ci-cd
PDF
Introduction to GitHub Actions
PDF
Git and git flow
Git and GitHub | Concept about Git and GitHub Process | Git Process overview
svn 능력자를 위한 git 개념 가이드
Gitlab flow solo
Using GitLab CI
JUNit Presentation
CI/CD with GitHub Actions
Jenkins CI
Why Aren't You Using Git Flow?
Gitlab ci, cncf.sk
MuleSoft Surat Meetup#42 - Runtime Fabric Manager on Self Managed Kubernetes ...
Git Lab Introduction
Git and GitHub
Yale Jenkins Show and Tell
GITS Class #16: CI/CD (Continuous Integration & Continuous Deployment) with G...
Getting Started with Kubernetes
CI CD Pipeline Using Jenkins | Continuous Integration and Deployment | DevOps...
Gitlab ci-cd
Introduction to GitHub Actions
Git and git flow
Ad

Similar to Jenkins multibranch pipeline workshop sep 2018 (20)

PDF
Software industrialization
PDF
Continuous Integration/Deployment with Docker and Jenkins
PDF
Continuous Integration with Open Source Tools - PHPUgFfm 2014-11-20
PDF
Minikube Workshop Handout
PDF
Going live with BommandBox and docker Into The Box 2018
PDF
Into The Box 2018 Going live with commandbox and docker
PPTX
CI/CD for android
PDF
Build your own clouds with Chef and MCollective
PDF
Jenkins-CI
PDF
Testable Infrastructure with Chef, Test Kitchen, and Docker
ODP
Scaling your jenkins master with docker
PDF
Continuous Integration using Jenkins with Python
PPTX
Blue Whale in an Enterprise Pond
PDF
JUC Europe 2015: Scaling Your Jenkins Master with Docker
PDF
Effective DevOps by using Docker and Chef together !
PDF
Jenkins Days - Workshop - Let's Build a Pipeline - Los Angeles
PDF
Dockerized maven
PDF
Chef & OpenStack: OSCON 2014
PDF
Docker and Puppet for Continuous Integration
PDF
Chef for OpenStack - OpenStack Fall 2012 Summit
Software industrialization
Continuous Integration/Deployment with Docker and Jenkins
Continuous Integration with Open Source Tools - PHPUgFfm 2014-11-20
Minikube Workshop Handout
Going live with BommandBox and docker Into The Box 2018
Into The Box 2018 Going live with commandbox and docker
CI/CD for android
Build your own clouds with Chef and MCollective
Jenkins-CI
Testable Infrastructure with Chef, Test Kitchen, and Docker
Scaling your jenkins master with docker
Continuous Integration using Jenkins with Python
Blue Whale in an Enterprise Pond
JUC Europe 2015: Scaling Your Jenkins Master with Docker
Effective DevOps by using Docker and Chef together !
Jenkins Days - Workshop - Let's Build a Pipeline - Los Angeles
Dockerized maven
Chef & OpenStack: OSCON 2014
Docker and Puppet for Continuous Integration
Chef for OpenStack - OpenStack Fall 2012 Summit
Ad

Recently uploaded (20)

PDF
DNT Brochure 2025 – ISV Solutions @ D365
PPTX
GSA Content Generator Crack (2025 Latest)
PPTX
Cybersecurity: Protecting the Digital World
PDF
Topaz Photo AI Crack New Download (Latest 2025)
PPTX
Custom Software Development Services.pptx.pptx
PPTX
Patient Appointment Booking in Odoo with online payment
PDF
Autodesk AutoCAD Crack Free Download 2025
PDF
Cost to Outsource Software Development in 2025
PDF
MCP Security Tutorial - Beginner to Advanced
PPTX
assetexplorer- product-overview - presentation
PPTX
"Secure File Sharing Solutions on AWS".pptx
PDF
Digital Systems & Binary Numbers (comprehensive )
PDF
How Tridens DevSecOps Ensures Compliance, Security, and Agility
DOCX
How to Use SharePoint as an ISO-Compliant Document Management System
PPTX
Tech Workshop Escape Room Tech Workshop
PDF
EaseUS PDF Editor Pro 6.2.0.2 Crack with License Key 2025
PDF
EN-Survey-Report-SAP-LeanIX-EA-Insights-2025.pdf
PDF
Complete Guide to Website Development in Malaysia for SMEs
PDF
How AI/LLM recommend to you ? GDG meetup 16 Aug by Fariman Guliev
PDF
Designing Intelligence for the Shop Floor.pdf
DNT Brochure 2025 – ISV Solutions @ D365
GSA Content Generator Crack (2025 Latest)
Cybersecurity: Protecting the Digital World
Topaz Photo AI Crack New Download (Latest 2025)
Custom Software Development Services.pptx.pptx
Patient Appointment Booking in Odoo with online payment
Autodesk AutoCAD Crack Free Download 2025
Cost to Outsource Software Development in 2025
MCP Security Tutorial - Beginner to Advanced
assetexplorer- product-overview - presentation
"Secure File Sharing Solutions on AWS".pptx
Digital Systems & Binary Numbers (comprehensive )
How Tridens DevSecOps Ensures Compliance, Security, and Agility
How to Use SharePoint as an ISO-Compliant Document Management System
Tech Workshop Escape Room Tech Workshop
EaseUS PDF Editor Pro 6.2.0.2 Crack with License Key 2025
EN-Survey-Report-SAP-LeanIX-EA-Insights-2025.pdf
Complete Guide to Website Development in Malaysia for SMEs
How AI/LLM recommend to you ? GDG meetup 16 Aug by Fariman Guliev
Designing Intelligence for the Shop Floor.pdf

Jenkins multibranch pipeline workshop sep 2018