jenkins 2.0 最新事情 〜make jenkins great again〜
TRANSCRIPT
Jenkins 2.0 Make Jenkins Great Again!
Miyata Jumpei (@miyajan)
Mar 18, 2017 Productivity Engineering - Forkwell Meetup #4
⾃⼰紹介
• 宮⽥ 淳平 (@miyajan)
• Cybozu
• ⽣産性向上チーム
• Jenkinsおじさん
Jenkins 2.0!
Background
History
• 2005 Hudson 1.0
• 2011 Forked to Jenkins
• 2016/04 Jenkins 2.0
Jenkins 1.0
• 10 years
• 100K active users
• 1000 plugins
• CI
•
• /UI
• Jenkins
• CI/CD
• UX
https://jenkins.io/blog/2016/04/26/jenkins-20-is-here/
$ docker run -p 8080:8080 jenkins:2.32.3# http://localhost:8080
Try Jenkins 2.0
Jenkins 2.0 Features
Suggested Plugins
•
•
• …
Jenkins 1.0
Suggested Plugins
•
•
• Pipeline, Git, Mail, Credential Binding, etc.
Jenkins 2.0
Pipeline
•
• Build Pipeline Plugin
• Delivery Pipeline Plugin
•
•
•
Jenkins 1.0
Pipeline Plugin
• DSL( )
• 1
•
• master
Jenkins 2.0
Pipeline DSL
GUI
•
•
• JobConfigHistory Plugin …
Jenkins 1.0
300 input
Pipeline as Code
• DSL(Groovy)
•
•
•
Jenkins 2.0
•
•
• https://github.com/jenkinsci/pipeline-plugin/blob/master/COMPATIBILITY.md
•
• https://github.com/jenkinsci/pipeline-plugin/blob/master/DEVGUIDE.md
Jenkins 2.0
Scripted Pipeline & Declarative Pipeline
Scripted Pipeline
• Pipeline
•
•
• try/catch…
Jenkins 2.0
node(‘has-docker’) { try { checkout scm stage(‘Build’) { sh ‘mvn clean install’ } stage(‘Archive’) { ( ) } if (currentBuild.result == 'SUCCESS') { mail to:"[email protected]", subject:"SUCCESS", body: "passed." } } catch (exc) { mail to:"[email protected]", subject:"FAILURE", body: "failed." } finally { deleteDir() }}
Declarative Pipeline
•
•
• Lint
Jenkins 2.0
pipeline { agent label:’has-docker’, dockerfile: true stages { stage("Build") { steps { sh 'mvn clean install' } } stage("Archive"){ ( ) } } post { always { deleteDir() } success { mail to:"[email protected]", subject:"SUCCESS", body: "passed." } failure { mail to:"[email protected]", subject:"FAILURE", body: "failed." } }}
Lint
•
• curl ssh lint
• https://github.com/jenkinsci/pipeline-model-definition-plugin/wiki/Validating-(or-linting)-a-Declarative-Jenkinsfile-from-the-command-line
• npm
• https://www.npmjs.com/package/jflint
Lint from CLI
• curl ssh lint
• https://github.com/jenkinsci/pipeline-model-definition-plugin/wiki/Validating-(or-linting)-a-Declarative-Jenkinsfile-from-the-command-line
• npm
• https://www.npmjs.com/package/jflint
• Declarative Pipeline
• “script” Scripted
Pipeline
Declarative Pipeline Examples
Build in Container
// simpleagent { docker “ubuntu:16.04”}
// specify label & argsagent { docker { image “ubuntu:16.04” label “docker-nodes” args “-v /tmp:/tmp -p 8000:8000” }}
Credentials
Credentials
environment { // type: secret text // SECRET_TEXT is defined SECRET_TEXT = credentials(‘SECRET_TEXT')
// type: username and password // SECRET_AUTH_USR and SECRET_AUTH_PSW are defined SECRET_AUTH = credentials('SECRET_AUTH')}
Options
pipeline { options { // 7 buildDiscarder(logRotator(daysToKeepStr: '7')) }}
Triggers
pipeline { triggers { cron('* * * * *') }}
Parallelstage("Commit") { steps { parallel( unitTest: { … }, staticAnalysis: { … }, package: { … } ) }}
Conditions
stage("Production") { when { branch "master" } steps { // deploy to production }}
Stashstage("Archive") { agent { docker “java:8” } steps { sh “gradle jar” stash name: “jar”, includes: “build/libs/*.jar” }}stage(“Deployment”) { agent { docker … } steps { unstash “jar” // jar }}
User Input
stage("Production") { steps { input “Ready to deploy?” }}
Syntax
• https://github.com/jenkinsci/pipeline-model-definition-plugin/wiki/Syntax-Reference
• https://jenkins.io/doc/book/pipeline/syntax/
Shared Libraries
•
• …
• subtree or submodule…?
Jenkins 1.0
Shared Libraries
• GitHub
• Groovy
• https://jenkins.io/doc/book/pipeline/shared-libraries/
Jenkins 2.0
Example: without Library
pipeline {… post { failure { // echo ‘failure!’ with red color ansiColor('xterm') { echo '\033[0;31mFailure!\033[0m' } } }…}
vars/echoErr.groovy
#!/usr/bin/env groovy
def call(String text) { ansiColor('xterm') { echo “\033[0;31m${text}\033[0m" }}
(repository root)+- vars- +- echoErr.groovy
Example: with Library
@Library('miyata-shared-libraries') _pipeline {… post { failure { echoErr ‘Failure!’ } }…}
GitHub
• push
• commit status
GitHub Plugin
•
•
commit status pending
commit status …
•
Jenkins 1.0
GitHub Organization Folder
• Organization
• Jenkinsfile Multibranch Pipeline GitHub
Jenkins 2.0
Multibranch Pipeline
•
• Jenkinsfile
•
Jenkins 2.0
• 1
•
• Webhook
• BitBucket
Blue Ocean
Classic Jenkins UI
• UX
Jenkins 1.0
Blue Ocean
• UX
•
• RC
•
• Blue Ocean Plugin
Jenkins 2.0
Pipeline Editor
Pipeline Editor
• Blue Ocean
• Jenkinsfile GUI
Jenkins 2.0
• LTS …
• LTS(stable)
•
GUI
•
•
• init.groovy.d ...
•
• https://github.com/jenkinsci/system-config-dsl-plugin
Best Practices
• Declarative Pipeline
• GitHub Organization Folder
• Blue Ocean
References
• https://jenkins.io/doc/
• https://jenkins.io/node/
• https://www.cloudbees.com/juc/agenda
Cybozu Meetup1
2 : https://cybozu.connpass.com/event/52668/