Top Banner
Jenkins Pipeline Плохой, Хороший, Декларативный
36

Jenkins Imperative Pipeline vs Declarative Pipeline

Jan 28, 2018

Download

Technology

Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Jenkins Imperative Pipeline vs Declarative Pipeline

Jenkins PipelineПлохой, Хороший, Декларативный

Page 2: Jenkins Imperative Pipeline vs Declarative Pipeline

@tolkv

@lavcraft

@aatarasoff

@aatarasoff

[email protected]

[email protected]

2

Page 3: Jenkins Imperative Pipeline vs Declarative Pipeline

DISCLAIMER

Наше мнение может не совпадать с официальной позицией наших работодателей, начальников, коллег или других специалистов.

Мы не претендуем на роль последней инстанции в вопросах использования той или иной технологии.

Все представленные решения вы можете использовать на свой страх и риск. За все ваши действия ответственность несёте только вы сами.

Все персонажи вымышлены, совпадения случайны.

Page 4: Jenkins Imperative Pipeline vs Declarative Pipeline
Page 5: Jenkins Imperative Pipeline vs Declarative Pipeline

5

Что делает Jenkins на JUG?

Page 6: Jenkins Imperative Pipeline vs Declarative Pipeline

План

● Что такое декларативный пайплайн?● Почему его стоит попробовать?● Немного теории● Демо● Делаем выводы

Page 7: Jenkins Imperative Pipeline vs Declarative Pipeline

7

Jenkins Pipeline

Page 8: Jenkins Imperative Pipeline vs Declarative Pipeline

Предпосылки к Declarative

Page 9: Jenkins Imperative Pipeline vs Declarative Pipeline

Структура

Page 10: Jenkins Imperative Pipeline vs Declarative Pipeline

Условные(conditional) функции

Page 11: Jenkins Imperative Pipeline vs Declarative Pipeline

Вариативность

Page 12: Jenkins Imperative Pipeline vs Declarative Pipeline

Declarative Pipeline 1.0Февраль 2017

Page 13: Jenkins Imperative Pipeline vs Declarative Pipeline

Declarative Pipeline 1.0Февраль 2017 Далее кратко – DP

Page 14: Jenkins Imperative Pipeline vs Declarative Pipeline

BlueOcean и DP = ❤

Page 15: Jenkins Imperative Pipeline vs Declarative Pipeline

Declarative Pipeline

durability

supportability

velocity

надежная сериализация

строгие правила расширения

порог входа и скорость изменений

15

Page 16: Jenkins Imperative Pipeline vs Declarative Pipeline

pipeline location and declaration

pipeline {

}

16

Page 17: Jenkins Imperative Pipeline vs Declarative Pipeline

Agent

agent any

● any● none● label● node (like label but with advanced options)● docker● dockerfile

17

Page 18: Jenkins Imperative Pipeline vs Declarative Pipeline

Stages and steps

stages {

stage('Example') {

steps {

echo 'Hello World'

}

}

}18

Page 19: Jenkins Imperative Pipeline vs Declarative Pipeline

Environment

environment {

MYKEY = credentials('my-prefined-secret-text')

}

steps {

sh 'printenv'

}

19

Page 20: Jenkins Imperative Pipeline vs Declarative Pipeline

Post → after steps

post {

success {

junit 'target/surefire-reports/**/*.xml'

}

}

20

Page 21: Jenkins Imperative Pipeline vs Declarative Pipeline

Post

● always

● success

● failure

● unstable

● changed

21

Page 22: Jenkins Imperative Pipeline vs Declarative Pipeline

Parameters

parameters {

string(

name: 'PERSON',

defaultValue: 'Mr Jenkins',

description: 'Who should I say hello to?'

)

}

22

Page 23: Jenkins Imperative Pipeline vs Declarative Pipeline

Parallel

parallel (

linux: {

build job: 'full-build-linux',

parameters: [string(name: 'GIT_BRANCH_NAME',

value: GIT_BRANCH)]

},

windows: {

build job: 'full-build-windows',

parameters: [string(name: 'GIT_BRANCH_NAME',

value: GIT_BRANCH)]

},

failFast: false

)

23

Page 24: Jenkins Imperative Pipeline vs Declarative Pipeline

When → expression

expression {

return readFile('pom.xml')

.contains('mycomponent')

}

expression { return A || B }

anyOf { branch 'master'; branch 'staging' } } 24

Page 25: Jenkins Imperative Pipeline vs Declarative Pipeline

When → expression

when {

branch 'production'

environment name: 'DEPLOY_TO',

value: 'production'

}

25

Page 26: Jenkins Imperative Pipeline vs Declarative Pipeline

When → expression

expression {

GIT_BRANCH = 'origin/' + sh(

returnStdout: true,

script: 'git rev-parse --abbrev-ref HEAD')

.trim()

return !(GIT_BRANCH == 'origin/master'

|| params.FORCE_FULL_BUILD)

}

} 26

Page 27: Jenkins Imperative Pipeline vs Declarative Pipeline

Options

● retry● timestamps● disableConcurrentBuilds● timeout

27

Page 28: Jenkins Imperative Pipeline vs Declarative Pipeline

Retry

stage('deploy-test') {

try {

build 'yourJob'

} catch(error) {

echo "First build failed, let's retry"

retry(2) {

input 'Retry the job ?'

build 'yourJob'

}

}

}

28

Page 29: Jenkins Imperative Pipeline vs Declarative Pipeline

Wait until

stage('deploy-test') {

waitUntil {

try {

build 'yourJob'

true

} catch(error) {

input "Retry the job ?"

currentBuild.result = 'SUCCESS'

false

}

}

}

29

Page 30: Jenkins Imperative Pipeline vs Declarative Pipeline

Хватит п***ть давай демо DP

30

Page 31: Jenkins Imperative Pipeline vs Declarative Pipeline

Script

script {

def browsers = ['chrome', 'firefox']

for (int i = 0; i < browsers.size(); ++i) {

echo "Testing the ${browsers[i]} browser"

}

}

31

Page 32: Jenkins Imperative Pipeline vs Declarative Pipeline

Declarative Pipeline. Demo

● перепишем всё используя новые знания● when { waitForQualityGate() ... } → steps { error '...' }

● script and shared args

32

Page 33: Jenkins Imperative Pipeline vs Declarative Pipeline

Императивный

→ Просто работает

→ Легко настраивается

→ Pipeline Hell

→ Нет структуры

→ CPS

Декларативный

→ Сложнее сломать*

→ Легче поддерживать

→ И распространять

→ За рамками дозволенного действовать

сложно

→ Документация пока страдает

→ Нет “простых” точек расширения

Page 34: Jenkins Imperative Pipeline vs Declarative Pipeline

Материалы

Jenkins Handbook

Jenkins Blog

Cloudbees Documentation

34

Jenkins Area Meetup JAM

Jenkins Moscow Meetup

@jenkins_ru

#jenkinsci_ru

https://github.com/aatarasoff/Jenkins-pipeline-live-demo

https://github.com/aatarasoff/spring-boot-example-for-jenkins-pipeline

https://github.com/lavcraft/jenkins-pipeline-libs-example

Page 35: Jenkins Imperative Pipeline vs Declarative Pipeline

https://alfalab.design/vacancies/java-razrabotchik

https://alfalab.design/vacancies/

Минутка маркетинга

Page 36: Jenkins Imperative Pipeline vs Declarative Pipeline

Спасибо! Готовы ответить на ваши вопросы

@tolkv

@aatarasoff

@lavcraft

@aatarasoff