50
CD with Jenkins Lessons Learned

Continuous Delivery with Jenkins: Lessons Learned

Embed Size (px)

Citation preview

Page 1: Continuous Delivery with Jenkins: Lessons Learned

CD with Jenkins

Lessons Learned

Page 2: Continuous Delivery with Jenkins: Lessons Learned

About meArchitect @

/aatarasoff

/aatarasoff

habrahabr.ru/aatarasoff

developerblog.info

Page 3: Continuous Delivery with Jenkins: Lessons Learned

Что такое Jenkins?

ПО для сборки артефактов?

Page 4: Continuous Delivery with Jenkins: Lessons Learned

Continuous Integration

Много людей - один артефакт

Синхронизация изменений, тестирование, code review

Цель - артефакт

Page 5: Continuous Delivery with Jenkins: Lessons Learned

Monolith Microservices

Page 6: Continuous Delivery with Jenkins: Lessons Learned

Continuous Integration Delivery

Page 7: Continuous Delivery with Jenkins: Lessons Learned

Continuous Delivery

Артефактов много

Не нужна синхронизация изменений

Цель - деплой в бой

Page 8: Continuous Delivery with Jenkins: Lessons Learned

Continuous Delivery Tools

Jenkins

GoCD

Team City

CircleCI

etc.

Page 9: Continuous Delivery with Jenkins: Lessons Learned

Почему Jenkins?

OpenSource

Экспертиза

Огромное количество интеграций

Pipeline Plugin

Page 10: Continuous Delivery with Jenkins: Lessons Learned

Lessons Learned

1. Линейный Pipeline

Page 11: Continuous Delivery with Jenkins: Lessons Learned

Линейная доставка

Независимые потоки доставки

Нет менеджмента зависимостей

Каждый артефакт готов работать в неполном окружении

Feature Toggle

Page 12: Continuous Delivery with Jenkins: Lessons Learned

Pipeline plugin

Декларативное описание процесса (Groovy DSL)

Очень просто сконфигурировать

Визуализация процесса

Page 13: Continuous Delivery with Jenkins: Lessons Learned
Page 14: Continuous Delivery with Jenkins: Lessons Learned

//checkout and definition stage node('build') { // Mark the code checkout 'stage' stage 'Checkout' git credentialsId: 'jenkins-git', url: "${git_url}/${repo}.git"

// Mark build 'stage' stage 'Build'

sh ('./gradlew clean dockerBuild final') }

//next steps

Page 15: Continuous Delivery with Jenkins: Lessons Learned

//checkout and definition stage node('build') { // Mark the code checkout 'stage' stage 'Checkout' git credentialsId: 'jenkins-git', url: "${git_url}/${repo}.git"

// Mark build 'stage' stage 'Build'

sh ('./gradlew clean dockerBuild final') }

//next steps

Page 16: Continuous Delivery with Jenkins: Lessons Learned

//checkout and definition stage node('build') { // Mark the code checkout 'stage' stage 'Checkout' git credentialsId: 'jenkins-git', url: "${git_url}/${repo}.git"

// Mark build 'stage' stage 'Build'

sh ('./gradlew clean dockerBuild final') }

//next steps

Page 17: Continuous Delivery with Jenkins: Lessons Learned

//checkout and definition stage node('build') { // Mark the code checkout 'stage' stage 'Checkout' git credentialsId: 'jenkins-git', url: "${git_url}/${repo}.git"

// Mark build 'stage' stage 'Build'

sh ('./gradlew clean dockerBuild final') }

//next steps

Page 18: Continuous Delivery with Jenkins: Lessons Learned

//checkout and definition stage node('build') { // Mark the code checkout 'stage' stage 'Checkout' git credentialsId: 'jenkins-git', url: "${git_url}/${repo}.git"

// Mark build 'stage' stage 'Build'

sh ('./gradlew clean dockerBuild final') }

//next steps

Page 19: Continuous Delivery with Jenkins: Lessons Learned

//checkout and definition stage node('build') { // Mark the code checkout 'stage' stage 'Checkout' git credentialsId: 'jenkins-git', url: "${git_url}/${repo}.git"

// Mark build 'stage' stage 'Build'

sh ('./gradlew clean dockerBuild final') }

//next steps

Page 20: Continuous Delivery with Jenkins: Lessons Learned

//checkout and definition stage node('build') { // Mark the code checkout 'stage' stage 'Checkout' checkout([$class: 'GitSCM', branches: [[name: '*/master']], doGenerateSubmoduleConfigurations: false, extensions: [

[$class: 'UserExclusion', excludedUsers: 'jenkins'], [$class: 'CleanBeforeCheckout'], [$class: 'LocalBranch', localBranch: 'master']

], userRemoteConfigs: [[ credentialsId: 'jenkins-git', url: "${git_url}/${artifact_name}.git", refspec: '+refs/heads/master:refs/remotes/origin/master' ]] ]) }

Page 21: Continuous Delivery with Jenkins: Lessons Learned

Blueocean plugin

Пока в стадии alpha

Красивая визуализация процесса на современных технологиях

Page 22: Continuous Delivery with Jenkins: Lessons Learned
Page 23: Continuous Delivery with Jenkins: Lessons Learned
Page 24: Continuous Delivery with Jenkins: Lessons Learned
Page 25: Continuous Delivery with Jenkins: Lessons Learned

Lessons Learned

1. Линейный Pipeline

2. Автогенерация джобов

Page 26: Continuous Delivery with Jenkins: Lessons Learned

Job DSL plugin

Декларативное описание создания джобов (Groovy DSL)

Очень просто сконфигурировать, легко смасштабировать

Унификация разработки как бонус

Page 27: Continuous Delivery with Jenkins: Lessons Learned
Page 28: Continuous Delivery with Jenkins: Lessons Learned

def jobs = "${JOBS_LIST}".split( '\n' )

jobs.each { job -> pipelineJob("${basePath}/${job}") { //define SCM

definition { cps { script(readFileFromWorkspace('some_script.groovy')) sandbox() } } } }

Page 29: Continuous Delivery with Jenkins: Lessons Learned

def jobs = "${JOBS_LIST}".split( '\n' )

jobs.each { job -> pipelineJob("${basePath}/${job}") { //define SCM

definition { cps { script(readFileFromWorkspace('some_script.groovy')) sandbox() } } } }

Page 30: Continuous Delivery with Jenkins: Lessons Learned

scm { git { remote { url "${some_url}.git" credentials 'jenkins-git' }

branch '*/master' createTag false } }

logRotator { numToKeep(3) }

concurrentBuild(false)

Page 31: Continuous Delivery with Jenkins: Lessons Learned

Lessons Learned

1. Линейный Pipeline

2. Автогенерация джобов

3. Даём управление человеку

Page 32: Continuous Delivery with Jenkins: Lessons Learned

А зачем нам человек?

Недостаточный уровень автоматизации

Невозможность принять решение go-nogo в автоматическом режиме

Формальные процедуры и процессы

Page 33: Continuous Delivery with Jenkins: Lessons Learned

Pipeline inputs

Дают возможность приостановить работу до принятия решения человеком

Есть REST API

Можно параметризовать

http://developerblog.info/2016/05/31/poluchaiem-upravlieniie-obratno-v-jenkins-pipeline/

Page 34: Continuous Delivery with Jenkins: Lessons Learned

input id: 'TestsArePassed'

http://host:port/job/name/number/input/TestsArePassed/proceedEmpty

http://host:port/job/name/number/input/TestsArePassed/abort

Page 35: Continuous Delivery with Jenkins: Lessons Learned

Jira Integration

Учётная система

Возможность назначать на определённые этапы ответственных лиц

Jira Plugin (есть интеграция с Pipeline Plugin)

Page 36: Continuous Delivery with Jenkins: Lessons Learned

jiraIssueUpdate( jqlSearch: jql, workflowActionName: 'Testing', comment: "Deploy to test environment is completed" )

jiraComment ( issueKey: jira_id, body: "Auto tests have been started» )

Page 37: Continuous Delivery with Jenkins: Lessons Learned

Lessons Learned

1. Линейный Pipeline

2. Автогенерация джобов

3. Даём управление человеку

4. Борьба с ограничениями

Page 38: Continuous Delivery with Jenkins: Lessons Learned

Не хватает возможностей?

Это OpenSource, всегда можно написать свой плагин или доработать существующий

Пул-реквесты не всегда будут приняты

… или будут приняты через продолжительное время

Page 39: Continuous Delivery with Jenkins: Lessons Learned

//checkout and definition stage node('build') { // Mark the code checkout 'stage' stage 'Checkout' checkout([$class: 'GitSCM', branches: [[name: '*/master']], doGenerateSubmoduleConfigurations: false, extensions: [

[$class: 'UserExclusion', excludedUsers: 'jenkins'], [$class: 'CleanBeforeCheckout'], [$class: 'LocalBranch', localBranch: 'master']

], userRemoteConfigs: [[ credentialsId: 'jenkins-git', url: "${git_url}/${artifact_name}.git", refspec: '+refs/heads/master:refs/remotes/origin/master' ]] ]) }

Page 40: Continuous Delivery with Jenkins: Lessons Learned

//checkout and definition stage node('build') { // Mark the code checkout 'stage' stage 'Checkout' git credentialsId: 'jenkins-git', url: "${git_url}/${repo}.git", excludedUsers: 'jenkins', cleanBeforeCheckout: true }

Удобно, но патч был отклонён

Page 41: Continuous Delivery with Jenkins: Lessons Learned

jiraIssueUpdate( jqlSearch: jql, workflowActionName: 'Testing', comment: 'Deploy to test environment is completed' )

Page 42: Continuous Delivery with Jenkins: Lessons Learned

jiraIssueUpdate( jqlSearch: jql, workflowActionName: 'Testing', comment: 'Deploy to test environment is completed' )

jiraIssueFieldUpdate( issueKey: jira_id, fieldName: 'Jenkins Info', fieldValue: 'some value'

)

Патч пока висит на рассмотрении

Page 43: Continuous Delivery with Jenkins: Lessons Learned

Не жди, используй Juseppe?

OpenSource UpdateCenter

Можно собирать свои версии плагинов раньше, чем они попадут в UpdateCenter

Решает проблемы с сетевым доступом (это когда у мастера нет доступа в интернет)

https://github.com/yandex-qatools/juseppe

Page 44: Continuous Delivery with Jenkins: Lessons Learned

Сетевые ограничения

Разные среды в разных DMZ

Сложно заказывать доступы между машинами

Решение в использовании slave-ов с разными лэйблами для разных сред/сетевых сегментов

Page 45: Continuous Delivery with Jenkins: Lessons Learned

Lessons Learned

1. Линейный Pipeline

2. Автогенерация джобов

3. Даём управление человеку

4. Борьба с ограничениями

5. Конфигурируй как код

Page 46: Continuous Delivery with Jenkins: Lessons Learned

Конфигурация как код

Не хочется делать Backup-ы

Команд много и есть желание быстро поднимать и конфигурировать новые экземпляры

Immutable-конфигурация

Page 47: Continuous Delivery with Jenkins: Lessons Learned

Блеск и нищета конфигурации

Легко конфигурировать джобы (см. JobDSL и Pipeline Plugin)

Добавлять мета-джобы можно через jenkins-cli

Сложно конфигурировать сам Jenkins: credentials, tools, plugins (шаблонизация xml, init groovy scripts, API etc.)

Page 48: Continuous Delivery with Jenkins: Lessons Learned

Lessons Learned

1. Линейный Pipeline

2. Автогенерация джобов

3. Даём управление человеку

4. Борьба с ограничениями

5. Конфигурируй как код

Page 49: Continuous Delivery with Jenkins: Lessons Learned

Plugins & tools List

JobDSL

Pipeline Plugin

Blueocean Plugin

Jira Plugin

Juseppe

Page 50: Continuous Delivery with Jenkins: Lessons Learned

/aatarasoff

/aatarasoff

habrahabr.ru/aatarasoff

developerblog.info

Вопросы и ответы

Architect @