Jenkins 2.0 (日本語)

Post on 06-Jan-2017

12.682 views 0 download

Transcript of Jenkins 2.0 (日本語)

©2016 CloudBees, Inc. All Rights Reserved 1©2016 CloudBees, Inc. All Rights Reserved

Jenkins 2.0川口耕介 / CTO / CloudBees, Inc.kk@kohsuke.org / @kohsukekawa

©2016 CloudBees, Inc. All Rights Reserved 2

自己紹介

• 川口耕介• Jenkins を作った人• CloudBees の最高技術責任者

©2016 CloudBees, Inc. All Rights Reserved 3

©2016 CloudBees, Inc. All Rights Reserved 4

©2016 CloudBees, Inc. All Rights Reserved 5

©2016 CloudBees, Inc. All Rights Reserved 6

ビルド・エージェント総数 (2016 年 4 月時点 )

400,000

©2016 CloudBees, Inc. All Rights Reserved 7Copyright HBO

©2016 CloudBees, Inc. All Rights Reserved 8Copyright HBO

©2016 CloudBees, Inc. All Rights Reserved 9http://en.wikipedia.org/wiki/File:Grand-Bazaar_Shop.jpg

©2016 CloudBees, Inc. All Rights Reserved 10

©2016 CloudBees, Inc. All Rights Reserved 11

©2016 CloudBees, Inc. All Rights Reserved 12

次の 10 年

©2016 CloudBees, Inc. All Rights Reserved 13

©2016 CloudBees, Inc. All Rights Reserved 14

©2016 CloudBees, Inc. All Rights Reserved 15

©2016 CloudBees, Inc. All Rights Reserved 16

#1: 広がりつづける自動化の波

©2016 CloudBees, Inc. All Rights Reserved 17

©2016 CloudBees, Inc. All Rights Reserved 18

©2016 CloudBees, Inc. All Rights Reserved 19

©2016 CloudBees, Inc. All Rights Reserved 20

©2016 CloudBees, Inc. All Rights Reserved 21Source: State of Jenkins Survey Sept. 2015

Jenkins の利用の拡大

©2016 CloudBees, Inc. All Rights Reserved 22

2013 調査 2015 調査

Jenkins はミッションクリティカルな存在ですか?

83% 92%

©2016 CloudBees, Inc. All Rights Reserved 23

2013 2015

ビルド 95% 97%

テスト 86% 90%

デプロイ 48% 58%

運用 15% 24%

Jenkins の用途は?

©2016 CloudBees, Inc. All Rights Reserved 24

どのレベルの自動化を達成しましたか?

59%30%

11%

 

CI

CD+手動デプロイCD+自動デプロイ

©2016 CloudBees, Inc. All Rights Reserved 25

©2016 CloudBees, Inc. All Rights Reserved 26

#2: コード→○  GUI→×  ステート→ ×

©2016 CloudBees, Inc. All Rights Reserved 27

コード→○  GUI→×  ステート→ ו 変更を見える化• 結果でなく意図を記録する• 冗長さを避ける• 大規模になっても大丈夫

©2016 CloudBees, Inc. All Rights Reserved 28Credit: https://flic.kr/p/nrFHFz

©2016 CloudBees, Inc. All Rights Reserved 29©2016 CloudBees, Inc. All Rights Reserved

パイプラインを作ってみよう

©2016 CloudBees, Inc. All Rights Reserved 30

パイプラインを作ってみよう

©2016 CloudBees, Inc. All Rights Reserved 31

パイプラインを作ってみよう

©2016 CloudBees, Inc. All Rights Reserved 32

パイプラインを作ってみよう

©2016 CloudBees, Inc. All Rights Reserved 33

Jenkinsfilenode('java8') { // Checkout our source code stage 'Checkout' checkout scm

// Build our project stage 'Build' sh 'mvn clean install'

// Run our test target stage 'Test' sh './test.sh'

// Archive our artifacts archive 'target/**/*.jar'}

©2016 CloudBees, Inc. All Rights Reserved 34

並列処理parallel( windows: { // run test on windows node('windows') { checkout scm sh './test.bat' } }, linux: { // run test on linux node('linux') { checkout scm sh './test.sh' } })

©2016 CloudBees, Inc. All Rights Reserved 35

クリーンアップ処理try { sh './test.sh'} finally { sh './clean.sh'}

©2016 CloudBees, Inc. All Rights Reserved 36

人間の作業を含めるdef releaseId = input( message:'リリースノートを更新してリリース IDを入力してください ', parameters: [ [$class: 'TextParameterDefinition', name: 'id'] ])sh "./upload.sh ${releaseId}"

©2016 CloudBees, Inc. All Rights Reserved 37

実行結果の表示

©2016 CloudBees, Inc. All Rights Reserved 38

GitHub Organization Folder

©2016 CloudBees, Inc. All Rights Reserved 39

Organization Folder の利点

• Jenkins の設定は一度だけ• Jenkinsfile をコミットするだけ• ブランチ別のビルド履歴• プルリクエストの自動ビルドと結果の通知

©2016 CloudBees, Inc. All Rights Reserved 40©2016 CloudBees, Inc. All Rights Reserved

パイプラインのドキュメント

jenkins.io/doc

©2016 CloudBees, Inc. All Rights Reserved 41

ドキュメント

©2016 CloudBees, Inc. All Rights Reserved 42

ドキュメント localhost:8080/workflow-cps-snippetizer/dslReference

©2016 CloudBees, Inc. All Rights Reserved 43©2016 CloudBees, Inc. All Rights Reserved

パイプラインでこんなことも

R Tyler Croy
problem statement needs more clarification on WHY we should be abstracting pipeline

©2016 CloudBees, Inc. All Rights Reserved 44

Docker イメージのビルド

def imageName = 'jenkinsciinfra/bind'

node('docker') {checkout scm

// Compute a unique image tagdef imageTag = "build-${env.BUILD_NUMBER}"

// The `docker` variable introduced by the pluginstage 'Build'def whale = docker.build("${imageName}:${imageTag}")

// Publish this image to Docker Hubstage 'Deploy'whale.push()

}

©2016 CloudBees, Inc. All Rights Reserved 45

ツールコンテナの活用

node('docker') {// The `docker` variable introduced by the plugin.//// Invoking our Gradle build inside a freshly spun up// Docker container with JDK8docker.image('java:8-jdk').inside {

checkout scmsh './gradlew --info'archive 'build/libs/**/*.jar'

}}

©2016 CloudBees, Inc. All Rights Reserved 46

プラグインが豊かにするパイプライン

node {...

if (env.BRANCH_NAME == 'master') {sshagent(credentials: ['my-credential-uuid']) {

sh './run-ssh-deploy-script'}

}}

©2016 CloudBees, Inc. All Rights Reserved 47

プラグインが豊かにするパイプライン

node {// Print timestamps for all the wrapped stepswrap([$class: 'TimestamperBuildWrapper']) {

checkout scmsh 'mvn clean install'

} // Archive our artifacts archive 'target/**/*.jar'}

github.com/jenkinsci/pipeline-examples

R Tyler Croy
Add screenshot for wrap() snippet generator
Kohsuke Kawaguchi
Transition: If plugins doesn't support custom steps, pipelien still provide a way to work with them

©2016 CloudBees, Inc. All Rights Reserved 48

プラグインが豊かにするパイプライン

node {stage "Build and test"timeout(time: 180, unit: 'MINUTES') {

sh "mvn clean install -Dmaven.repo.local=${pwd()}/.repository"}

stage "Archive test results"step([$class: 'JUnitResultArchiver',

healthScaleFactor: 20.0,testResults: '**/target/surefire-reports/*.xml'])

}

R Tyler Croy
Add screenshot for snippet generator

©2016 CloudBees, Inc. All Rights Reserved 49©2016 CloudBees, Inc. All Rights Reserved

パイプラインの抽象化と再利用

R Tyler Croy
problem statement needs more clarification on WHY we should be abstracting pipeline

©2016 CloudBees, Inc. All Rights Reserved 50

Docker イメージのビルド x100 ?

def imageName = 'jenkinsciinfra/bind'

node('docker') {checkout scm

// Compute a unique image tagdef imageTag = "build-${env.BUILD_NUMBER}"

// The `docker` variable introduced by the pluginstage 'Build'def whale = docker.build("${imageName}:${imageTag}")

// Publish this image to Docker Hubstage 'Deploy'whale.push()

}

©2016 CloudBees, Inc. All Rights Reserved 51

container_build 'jenkinsciinfra/bind'

©2016 CloudBees, Inc. All Rights Reserved 52

vars/container_build.groovy

def call(imageName) { node('docker') {

checkout scm

// Compute a unique image tagdef imageTag = "build-${env.BUILD_NUMBER}"

// The `docker` variable introduced by the pluginstage 'Build'def whale = docker.build("${imageName}:${imageTag}")

// Publish this image to Docker Hubstage 'Deploy'whale.push()

}}

©2016 CloudBees, Inc. All Rights Reserved 53

まとめ : パイプライン

• 複雑な処理が必要な時にうってつけ• テキストで記述してバージョン管理• ジョブが多くてもテンプレート化• Jenkins を再起動しても続く

©2016 CloudBees, Inc. All Rights Reserved 54

©2016 CloudBees, Inc. All Rights Reserved 55

#3: UI の改善

©2016 CloudBees, Inc. All Rights Reserved 56

#4: 「要組み立て」からの脱却

©2016 CloudBees, Inc. All Rights Reserved 57

©2016 CloudBees, Inc. All Rights Reserved 58

©2016 CloudBees, Inc. All Rights Reserved 59

• お勧めプラグインが最初からついてくる–8割の機能を最初から搭載–ベスト・プラクティスにユーザーを誘導する

Jenkins 2.0 では…

©2016 CloudBees, Inc. All Rights Reserved 60

• プラグイン同士がオーバーラップする部分の面倒を見られる

• 開発と QA 資源の集中

標準の機能を豊かにするメリット

©2016 CloudBees, Inc. All Rights Reserved 61

ドキュメンテーション

©2016 CloudBees, Inc. All Rights Reserved 62

#5: ユーザーを守る

©2016 CloudBees, Inc. All Rights Reserved 63https://flic.kr/p/otBTLe

©2016 CloudBees, Inc. All Rights Reserved 64

• セキュリティ・チームの発足• セキュリティ・チームとリリース・チーム

の連携• セキュリティ勧告と事前アナウンスメント• アプリ内でのユーザーの誘導

今までも一歩一歩改善してきた

©2016 CloudBees, Inc. All Rights Reserved 65

• 最初からより安全なディフォルト

2.0 ではまた一歩先へ

©2016 CloudBees, Inc. All Rights Reserved 66

• 一からやり直したわけではなく、コアは1.x と同じ系列

• 今までと同じアップデートの仕方で!

後方互換性もバッチリ

©2016 CloudBees, Inc. All Rights Reserved 67

まとめ : Jenkins 2.0• Pipeline as Code• UI の改善• 「要組み立て」からの脱却• セキュリティ

• CI → CD へ