Let’s learn Jenkins with handson
Why Jenkins?
Jenkins Plugins
Jenkins Pipelines
Managing Jenkins
docker run -u 0 --privileged -d -p 8080:8080 -p 50000:50000 -v jenkins_home:/var/jenkins_home -v $(which docker):/usr/bin/docker -v /var/run/docker.sock:/var/run/docker.sock jenkins/jenkins:lts
Go to http://localhost:8080
Declarative Pipeline
Scripted Pipeline
pipeline {
agent any
stages {
stage('Hello') {
steps {
echo 'Hello World'
}
}
}
}
pipeline {
agent { docker { image 'ruby:2.6.6-alpine' }}
stages {
stage('Version check') {
steps {
sh 'ruby --version'
}
}
}
}
Use contents from this folder for building image
cd to calculator_as_interpreter in https://github.com/slashpai/docker_k8s_training/tree/main/docker_apps
pipeline {
agent { docker { image 'calculator_interpreter:v1' }}
stages {
stage('Sum 2 + 3') {
steps {
sh 'ruby /app/calculator.rb 2 + 3'
}
}
stage('Diff 2 - 3') {
steps {
sh 'ruby /app/calculator.rb 2 - 3'
}
}
}
}
pipeline {
agent any
parameters {
string(name: 'PERSON', defaultValue: 'Mr Jenkins', description: 'Who should I say hello to?')
text(name: 'BIOGRAPHY', defaultValue: '', description: 'Enter some information about the person')
booleanParam(name: 'TOGGLE', defaultValue: true, description: 'Toggle this value')
choice(name: 'CHOICE', choices: ['One', 'Two', 'Three'], description: 'Pick something')
password(name: 'PASSWORD', defaultValue: 'SECRET', description: 'Enter a password')
}
stages {
stage('Example') {
steps {
echo "Hello ${params.PERSON}"
echo "Biography: ${params.BIOGRAPHY}"
echo "Toggle: ${params.TOGGLE}"
echo "Choice: ${params.CHOICE}"
echo "Password: ${params.PASSWORD}"
}
}
}
}
pipeline {
agent any
stages {
stage('Hello') {
steps {
echo 'Hello World'
}
}
stage('Parallel Stages') {
parallel {
stage('parallel 1') {
steps {
echo 'Hello from Parallel Stage 1'
}
}
stage('parallel 2') {
steps {
echo 'Hello from Parallel Stage 2'
}
}
}
}
}
}
More options: https://www.jenkins.io/doc/book/pipeline/syntax/
Jenkins.instance.queue.clear()
Why Jenkins?
Jenkins Pipelines
Helpful plugins
Managing Jenkins