43
Jenkins Pipeline + Blue Ocean スクラッチ からの継続的デリバリ

[DO02] Jenkins PipelineとBlue Oceanによる、フルスクラッチからの継続的デリバリ

Embed Size (px)

Citation preview

Jenkins Pipeline + Blue Oceanフルスクラッチからの継続的デリバリ

2© 2017 CloudBees, Inc. All Rights Reserved.

川口耕介とは

• Jenkinsプロジェクトの父

• CloudBeesのCTO

3© 2017 CloudBees, Inc. All Rights Reserved.

継続的デリバリとは

Development Production

Commit Build Test Stage Deploy

Feedback Loop

$The Business

4© 2017 CloudBees, Inc. All Rights Reserved.

Software changes continuously deployed

to live production

Continuous Deployment

Software changes continuously delivered to stakeholders in any

environment

Continuous Delivery

Software changes continuously delivered to stakeholders in any

environment

Continuous DeliveryContinuous Integration

Automated commit, build and testing of code in the development environment

DevOps Cultural approaches & technical practices

User FeedbackRapid Changes

Dis

cipl

ine

AGILE

An incremental approach to identifying,

prioritizing, and coordinating feature

development

Development Production / Prod-like Live ProductionEnv.

Stag

e

Release Deploy Monitor

Upstream (left) Downstream (right)Define Plan Code Compile Build Unit Test Analyze Integrate Int. Test Package Place Load Test Acct. Test

Change Mgt. Production Bugs

なぜ継続的デリバリ?

5© 2017 CloudBees, Inc. All Rights Reserved.

Jenkins Pipeline• Pipeline as Code

• 継続的デリバリのプロセスの定義を記述する

• リポジトリにJenkinsfileとしてコミットする

• jenkins.io/doc/book/pipeline

6© 2017 CloudBees, Inc. All Rights Reserved.https://flic.kr/p/opw1JR

Blue Ocean

7© 2017 CloudBees, Inc. All Rights Reserved.

8© 2017 CloudBees, Inc. All Rights Reserved.

9© 2017 CloudBees, Inc. All Rights Reserved.

10© 2017 CloudBees, Inc. All Rights Reserved.

11© 2017 CloudBees, Inc. All Rights Reserved.

kohsuke/jhipster-sample-app

ツール

• Maven• Node / Gulp• Gatling• Docker

本日の材料

パイプラインを設計

13© 2017 CloudBees, Inc. All Rights Reserved.

開発者個別

• ビルド

• 単体テスト

• 静的解析

チーム全体

• ビルド

• 単体テスト

• 静的解析

QA環境

• デプロイ

• 性能テスト

本番環境

• デプロイ

パイプラインを設計

14© 2017 CloudBees, Inc. All Rights Reserved.

ブランチ戦略を設計

master

qa

production

15© 2017 CloudBees, Inc. All Rights Reserved.

docker run -p 8080:8080 –u root ¥-v /var/run/docker.sock:/var/run/docker.sock ¥-v $PWD/jenkins_home:/var/jenkins_homejenkinsci/blueocean

Jenkins + Blue Oceanを起動

16© 2017 CloudBees, Inc. All Rights Reserved.

17© 2017 CloudBees, Inc. All Rights Reserved.

ビルド

19© 2017 CloudBees, Inc. All Rights Reserved.

• Jenkins Pipelineはビルドシステムではない!

• 既存のビルドシステムを他とくっつける糊のようなもの

• ゴール

• 再現性のあるポータブルなビルド

• バイナリを作って後のために保存

• 今回はMavenを使います

ビルド

20© 2017 CloudBees, Inc. All Rights Reserved.

pipeline {agent anystages {

stage('Build') {steps {

sh 'mvn'}

}}

}

ビルド

21© 2017 CloudBees, Inc. All Rights Reserved.

stage('Build') {agent {

docker {image 'maven:3-alpine'

}}/* .. */

}

ビルド

22© 2017 CloudBees, Inc. All Rights Reserved.

stage('Build') {agent ...steps {

sh 'mvn clean install'archiveArtifacts 'target/*.war'junit 'target/surefire-reports/*.xml'

}}

ビルド

23© 2017 CloudBees, Inc. All Rights Reserved.

stage('Build') {/* .. */steps {

withMaven {sh 'mvn clean package'

}}

}

プラグインを使って頻出パターンを簡略化

24© 2017 CloudBees, Inc. All Rights Reserved.

stage('Build') {/* .. */steps {

withMaven(mavenSettingsConfig:'my-maven-settings') {sh 'mvn clean package'

}}

}

CIビルド環境に適応

単体テスト

26© 2017 CloudBees, Inc. All Rights Reserved.

stage('Frontend Test') {agent { docker 'node:alpine' }steps {

sh 'yarn install'sh 'yarn global add gulp-cli'sh 'gulp test'

}}

フロントエンドの単体テスト

27© 2017 CloudBees, Inc. All Rights Reserved.

stage('Frontend Test') {agent { docker 'node:alpine' }steps {

sh 'yarn install'sh 'yarn global add gulp-cli'sh 'gulp test'junit 'target/test-results/karma/*.xml'

}}

結果の捕捉

静的解析

29© 2017 CloudBees, Inc. All Rights Reserved.

いろいろなオプションがある

• FindBugs• PMD• Checkstyle• …

SonarQube?• jenkins.io/blog/2017/04/18/continuousdelivery-devops-sonarqube/

静的解析

30© 2017 CloudBees, Inc. All Rights Reserved.

pipeline {agent anystages {

stage('Analyze') {agent ...steps {

withMaven {sh 'mvn pmd:pmd'pmd pattern:'target/pmd.xml'

}}

}}

}

PMDの例

QA環境

32© 2017 CloudBees, Inc. All Rights Reserved.

開発者個別

• ビルド

• 単体テスト

• 静的解析

チーム全体

• ビルド

• 単体テスト

• 静的解析

QA環境

• デプロイ

• 性能テスト

本番環境

• デプロイ

パイプラインの設計

33© 2017 CloudBees, Inc. All Rights Reserved.

• Jenkins Pipelineはデプロイメント・システムではない!

• 既存のデプロイメント・システムを他とくっつける糊のようなもの

• 所変われば…• AWS/Azure• Chef/Puppet• アップストアへ登録

• 社内サーバにアップロード

デプロイ

34© 2017 CloudBees, Inc. All Rights Reserved.

pipeline {agent anystages {

stage('Deploy to QA') {steps {

sh './deploy.sh'}

}}

}

デプロイ

35© 2017 CloudBees, Inc. All Rights Reserved.

pipeline {agent anystages {

stage('Deploy to QA') {when { branch 'qa' }steps {

sh './deploy.sh'}

}}

}

qaブランチのみで実行

本番環境

37© 2017 CloudBees, Inc. All Rights Reserved.

開発者個別

• ビルド

• 単体テスト

• 静的解析

チーム全体

• ビルド

• 単体テスト

• 静的解析

QA環境

• デプロイ

• 性能テスト

本番環境

• デプロイ

パイプラインの設計

38© 2017 CloudBees, Inc. All Rights Reserved.

stage(‘Deploy to Production') {steps {

input message: 'Deploy to production?',ok: 'Fire zee missiles!'

sh './deploy.sh prod'}

}

確認

39© 2017 CloudBees, Inc. All Rights Reserved.

確認

これで完成?

41© 2017 CloudBees, Inc. All Rights Reserved.

• 継続的デリバリの実現には開発者へのフィードバックが欠かせない

• パイプラインを使って

• メールを送る

• HipChat/Slack通知

• JIRAチケットの更新

• jenkins.io/node/tags/notifications/

フィードバックループを作る

Q & A

43© 2017 CloudBees, Inc. All Rights Reserved.

jenkins.io/doc/book/pipeline

jenkins.io/projects/blueocean

Docker コンテナ

• jenkinsci/jenkins:lts-alpine• jenkinsci/blueocean

[email protected]

資料