40 Jenkins features and plugins you wished you had known about - - PowerPoint PPT Presentation

40 jenkins features and plugins you
SMART_READER_LITE
LIVE PREVIEW

40 Jenkins features and plugins you wished you had known about - - PowerPoint PPT Presentation

40 Jenkins features and plugins you wished you had known about before! Joep Weijers (TOPdesk) Which CI server do you use? https://snyk.io/blog/jvm-ecosystem-report-2018-tools https://wiki.jenkins.io/display/JENKINS/Logo


slide-1
SLIDE 1

40 Jenkins features and plugins you wished you had known about before!

Joep Weijers (TOPdesk)

slide-2
SLIDE 2

https://snyk.io/blog/jvm-ecosystem-report-2018-tools

Which CI server do you use?

slide-3
SLIDE 3

https://wiki.jenkins.io/display/JENKINS/Logo

slide-4
SLIDE 4

https://medium.com/@ricardoespsanto/jenkins-is-dead-long-live-concourse-ce13f94e4975

slide-5
SLIDE 5

Used with permission from Cloudbees

slide-6
SLIDE 6

(1) Set-up: Use docker

slide-7
SLIDE 7

wget -q -O - https://pkg.jenkins.io/debian/jenkins.io.key | sudo apt-key add - sudo sh -c 'echo deb http://pkg.jenkins.io/debian-stable binary/ > /etc/apt/sources.list.d/jenkins.list' sudo apt-get update sudo apt-get install jenkins

slide-8
SLIDE 8

wget -q -O - https://pkg.jenkins.io/debian/jenkins.io.key | sudo apt-key add - sudo sh -c 'echo deb http://pkg.jenkins.io/debian-stable binary/ > /etc/apt/sources.list.d/jenkins.list' sudo apt-get update sudo apt-get install jenkins

slide-9
SLIDE 9

docker run -p 8080:8080 -p 50000:50000 \

  • v $PWD/jenkins:/var/jenkins_home \

jenkins/jenkins:lts

slide-10
SLIDE 10

docker run -p 8080:8080 -p 50000:50000 \

  • v $PWD/jenkins:/var/jenkins_home \

jenkins/jenkins:lts *********************************************** Please use the following password to proceed to installation: 06ac817e24324166880761bae911faf2

slide-11
SLIDE 11

(2) Set-up: Use the jenkins/jenkins Docker images

slide-12
SLIDE 12

DEPRECATED: USE: Weekly releases LTS release

slide-13
SLIDE 13

(3) Set-up: First time installer & Plugins

slide-14
SLIDE 14
slide-15
SLIDE 15

Use this!

slide-16
SLIDE 16
slide-17
SLIDE 17

(4) Set-up: Provision your plugins

slide-18
SLIDE 18

docker exec -it [containerId] /usr/local/bin/install- plugins.sh [plugins]

slide-19
SLIDE 19

docker exec -it [containerId] /usr/local/bin/install- plugins.sh [plugins] http://[jenkinsurl]/safeRestart

slide-20
SLIDE 20

FROM jenkins/jenkins:lts COPY plugins.txt /usr/share/jenkins/ref/plugins.txt RUN /usr/local/bin/install-plugins.sh < /usr/share/jenkins/ref/plugins.txt

slide-21
SLIDE 21

(5) Set-up: Configure your plugins using Jenkins Configuration as Code

slide-22
SLIDE 22

https://jenkins.io/projects/jcasc/

slide-23
SLIDE 23

(6) Set-up: Don’t do work on the Master, use Agents

slide-24
SLIDE 24
slide-25
SLIDE 25
slide-26
SLIDE 26
slide-27
SLIDE 27
slide-28
SLIDE 28
slide-29
SLIDE 29

(7) Set-up: Provision agents using Swarm plugin

slide-30
SLIDE 30

https://plugins.jenkins.io/swarm

slide-31
SLIDE 31

(8) Set-up: Automate agent provisioning and make them ephemeral

slide-32
SLIDE 32

https://snyk.io/blog/jvm-ecosystem-report-2018-tools

Which build tool do you use for your main project?

slide-33
SLIDE 33

(9) Jobs: Don't use Maven job

slide-34
SLIDE 34
slide-35
SLIDE 35
slide-36
SLIDE 36

(10) Jobs: Pipeline: Job configuration as code

slide-37
SLIDE 37
slide-38
SLIDE 38

Jenkinsfile

slide-39
SLIDE 39

pipeline { agent any stages { stage('Hello World') { steps { sh 'echo Hello world' } } } }

slide-40
SLIDE 40

(11) Jobs: Pipeline: Stages are groups of steps

slide-41
SLIDE 41

stages { stage('Build’) { … } stage('Test’) { … } stage('Deploy') { … } stage('E2E') { … } stage('Perf test') { … } stage('Acc') { … } stage('Prod') { … } }

slide-42
SLIDE 42
slide-43
SLIDE 43

(12) Jobs: Pipeline: Do work on agents…

slide-44
SLIDE 44

pipeline { agent any stages { stage('Hello World') { steps { sh 'echo Hello world' } } } }

slide-45
SLIDE 45

pipeline { agent any stages { stage('Hello World') { steps { sh 'echo Hello world' } } } }

slide-46
SLIDE 46

(13) Jobs: Pipeline: Do work on agents… … unless you’re waiting for user input

slide-47
SLIDE 47
slide-48
SLIDE 48

pipeline { agent none stages { stage('Do work') { agent any steps { … } } stage('Input requested') { agent none steps { input message: 'user input' } }

slide-49
SLIDE 49

pipeline { agent none stages { stage('Do work') { agent any steps { … } } stage('Input requested') { agent none steps { input message: 'user input' } }

slide-50
SLIDE 50

pipeline { agent none stages { stage('Do work') { agent any steps { … } } stage('Input requested') { agent none steps { input message: 'user input' } }

slide-51
SLIDE 51

pipeline { agent none stages { stage('Do work') { agent any steps { … } } stage('Input requested') { agent none steps { input message: 'user input' } }

slide-52
SLIDE 52

(14) Jobs: Pipeline: Docker image as agent

slide-53
SLIDE 53

pipeline { agent { docker { image 'node:7-alpine' } } stages { stage('Test') { steps { sh 'node --version' } } } }

slide-54
SLIDE 54

(15) Jobs: Pipeline: Docker image as agent with persistent storage

slide-55
SLIDE 55

pipeline { agent { docker { image 'maven:3-alpine' args '-v $HOME/.m2:/root/.m2' } } stages { stage('Build') { steps { sh 'mvn -B' }}}}

slide-56
SLIDE 56

(16) Jobs: Pipeline: Stashing files

slide-57
SLIDE 57

stage('Build') { agent any steps { checkout scm sh 'make' stash includes: '**/target/*.jar', name: 'app' } } stage('Test on Linux') { agent { label 'linux' } steps { unstash 'app' sh 'make check' } }

slide-58
SLIDE 58

(17) Jobs: Pipeline: Locking resources

slide-59
SLIDE 59

echo 'Starting' lock('my-resource-name') { echo 'I require unique access to the resource' // any other build will wait until the one locking // the resource leaves this block } echo 'Finish'

slide-60
SLIDE 60

(18) Jobs: Pipeline: Parameters are an option

slide-61
SLIDE 61

pipeline { agent any parameters { string(description: 'foo', name: 'bar') } environment { baz = params.bar }

slide-62
SLIDE 62

(19) Jobs: Pipeline: Parallelism

slide-63
SLIDE 63

parallel 'end-to-end-tests’: { // E2E }, 'performance-tests’: { // Perf tests }

slide-64
SLIDE 64

parallel 'end-to-end-tests’: { // E2E node('e2e-node'){ … } }, 'performance-tests’: { // Perf tests node('perf-test-node'){ … } }

slide-65
SLIDE 65

def splits = splitTests count(2) def branches = [:] for (int i = 0; i < splits.size(); i++) { def index = i branches["split${i}"] = { def exclusions = splits.get(index); // mvn test excludes exclusions } } parallel branches

slide-66
SLIDE 66

stash name: 'sources', includes: 'pom.xml,src/' def splits = splitTests count(2) def branches = [:] for (int i = 0; i < splits.size(); i++) { def index = i branches["split${i}"] = { node('remote') { unstash 'sources' def exclusions = splits.get(index); writeFile file: 'exclusions.txt', text: exclusions.join("\n") "${tool 'M3'}/bin/mvn -B -Dmaven.test.failure.ignore test" junit 'target/surefire-reports/*.xml' }}} parallel branches

slide-67
SLIDE 67

(20) Jobs: Pipeline: Know the difference between Declarative and Scripted

slide-68
SLIDE 68

Declarative Scripted Easy to use Bit harder due to more Groovy Concise Boilerplate Validation before running Try-commit-retry-commit-loop Visual Editor Groovy editor

slide-69
SLIDE 69

Declarative Scripted Easy to use Bit harder due to more Groovy Concise Boilerplate Validation before running Try-commit-retry-commit-loop Visual Editor Groovy editor

  • -------------------------------- +
  • -------------------------------- +

Perfect for regular users More flexiblity for power users

slide-70
SLIDE 70

(21) Jobs: Pipeline: Keep your Pipelines small

slide-71
SLIDE 71

(22) Jobs: Pipeline: @NonCPS

slide-72
SLIDE 72

Continuation-passing style (CPS)

slide-73
SLIDE 73

@NonCPS static def prepareDeploymentYaml(text, binding) { return new groovy.text.StreamingTemplateEngine() .createTemplate(text) .make(binding) .toString() }

slide-74
SLIDE 74

(23) Jobs: Pipeline: Aborting Pipelines

slide-75
SLIDE 75
slide-76
SLIDE 76
slide-77
SLIDE 77
slide-78
SLIDE 78

(24) Jobs: Pipeline: Blue ocean GUI

slide-79
SLIDE 79
slide-80
SLIDE 80
slide-81
SLIDE 81
slide-82
SLIDE 82

(25) Jobs: Pipeline: There is a Pipeline editor

slide-83
SLIDE 83
slide-84
SLIDE 84

(26) Jobs: Pipeline: Use Shared libraries

slide-85
SLIDE 85

Don’t Repeat Yourself!

slide-86
SLIDE 86

(27) Jobs: Pipeline: Use files from shared libraries

slide-87
SLIDE 87

(28) Jobs: Pipeline: Developing your shared libraries

slide-88
SLIDE 88
slide-89
SLIDE 89

(29) Views: Build your own view

slide-90
SLIDE 90
slide-91
SLIDE 91
slide-92
SLIDE 92
slide-93
SLIDE 93
slide-94
SLIDE 94
slide-95
SLIDE 95
slide-96
SLIDE 96

(30) Views: Less mails, more Build Monitor

slide-97
SLIDE 97
slide-98
SLIDE 98
slide-99
SLIDE 99
slide-100
SLIDE 100

(31) There is an API

slide-101
SLIDE 101

[jenkins url]/api/ [jenkins url]/job/myJob/api/

slide-102
SLIDE 102

[jenkins url]/user/admin/my- views/view/MyJobs/api/json?tree=jobs[color]

slide-103
SLIDE 103

{ "_class" : "com.smartcodeltd.jenkinsci.plugins.buildmonitor.BuildMonitorView", "jobs" : [ { "_class" : "hudson.model.FreeStyleProject", "color" : "yellow" }, { "_class" : "hudson.model.FreeStyleProject", "color" : "blue" }, { "_class" : "org.jenkinsci.plugins.workflow.job.WorkflowJob", "color" : "blue_anime" } ] }

slide-104
SLIDE 104

(32) Views: Extreme feedback

slide-105
SLIDE 105
slide-106
SLIDE 106

https://techblog.topdesk.com/

slide-107
SLIDE 107

(33) Build numbers are more than integers

slide-108
SLIDE 108

http://localhost:8080/job/myJob/4/

slide-109
SLIDE 109
slide-110
SLIDE 110

http://localhost:8080/job/myJob/lastBuild/

slide-111
SLIDE 111

http://localhost:8080/job/myJob/lastBuild/ lastBuild lastStableBuild lastSuccessfulBuild lastFailedBuild lastUnstableBuild lastUnsuccessfulBuild lastCompletedBuild

slide-112
SLIDE 112

(34) Jenkins X

slide-113
SLIDE 113

https://jenkins-x.io/

slide-114
SLIDE 114

(35) Security: Stay up to date

slide-115
SLIDE 115
slide-116
SLIDE 116
slide-117
SLIDE 117
slide-118
SLIDE 118
slide-119
SLIDE 119
slide-120
SLIDE 120

(36) Security: Warnings: CSRF crumb

slide-121
SLIDE 121
slide-122
SLIDE 122

curl -u "admin:admin" 'http://localhost:8080/crumbIssuer/api/xml?xpath=concat(/ /crumbRequestField,":",//crumb)'

slide-123
SLIDE 123

curl -u "admin:admin" 'http://localhost:8080/crumbIssuer/api/xml?xpath=concat(/ /crumbRequestField,":",//crumb)' Jenkins-Crumb:bc22da3c06187f7c042abeb72419d835

slide-124
SLIDE 124

curl -u "admin:admin" 'http://localhost:8080/crumbIssuer/api/xml?xpath=concat(/ /crumbRequestField,":",//crumb)' Jenkins-Crumb:bc22da3c06187f7c042abeb72419d835 curl -X POST -u "admin:admin" -H "Jenkins- Crumb:bc22da3c06187f7c042abeb72419d835" http://localhost:8080/job/someJob/build

slide-125
SLIDE 125

(37) Security: Warnings: JNLP

slide-126
SLIDE 126
slide-127
SLIDE 127

(38) Learn about Cloudbees

slide-128
SLIDE 128

(39) Enterprise Jenkins: Cloudbees

slide-129
SLIDE 129
slide-130
SLIDE 130

(40) My favorite plugins

slide-131
SLIDE 131

Build Monitor Job Config History Job DSL Throttle Concurrent Builds Timestamper Version number plugin & Build-name-setter

slide-132
SLIDE 132

40 Jenkins features and plugins you wished you had known about before!

Stack Overflow: https://stackoverflow.com/questions/tagged/jenkins Read our TechBlog: http://techblog.topdesk.com Twitter: @joepweijers