pipeline as code - new feature in jenkins 2

27
Pipeline as code with Multibranch Workflows in Jenkins 2

Upload: michal-ziarnik

Post on 16-Apr-2017

318 views

Category:

Technology


2 download

TRANSCRIPT

Page 1: Pipeline as code - new feature in Jenkins 2

Pipeline as codewith Multibranch Workflows in Jenkins 2

Page 2: Pipeline as code - new feature in Jenkins 2

JenkinsOpen source CI/CD projectOn premise toolSupports pluginsIntegrates with 3rd party tools and services

Page 3: Pipeline as code - new feature in Jenkins 2
Page 4: Pipeline as code - new feature in Jenkins 2

Organisation folder

Workflow Multibranch

Pipeline

New in Jenkins 2

Page 5: Pipeline as code - new feature in Jenkins 2

Workflow MultibranchAutomatic Workflow (job) creation in Jenkins per new

branch in the repository (assuming webhooks are registered from SCM to Jenkins)

Build specific to that child-branch and its unique scm change and build history

Automatic job pruning/deletion for branches deleted from the repository, according to the settings

Flexibility to individually configure branch properties, by overriding the parent properties, if required

* Source: Jenkins.io

Page 6: Pipeline as code - new feature in Jenkins 2

Organisation folderWorks on project space level within organisation SCM. Provides ability to create and manage workflow jobs for

all repositoriesAutomatically removes jobs for merged back branchesSimplified configuration that requires only project name

and credentialsProvides pull request testing functionality. Jenkins will

create a new CD pipeline when a pull-request is submitted and build/test the pull-request.

Page 7: Pipeline as code - new feature in Jenkins 2

Setting up Organisation folder

Page 8: Pipeline as code - new feature in Jenkins 2
Page 9: Pipeline as code - new feature in Jenkins 2

Pipeline execution

Page 10: Pipeline as code - new feature in Jenkins 2

Pipeline definitionPipelines are “Jenkins job definitions” enabled by the

Pipeline pluginBased on Groovy programming languagePipelines leverage the power of multiple steps to

execute both simple and complex tasks according to parameters that you establish

Pipelines can build code and orchestrate the work required to drive applications from commit to delivery

* Source: Jenkins.io

Page 11: Pipeline as code - new feature in Jenkins 2

Pipeline attributesDurable: Pipelines can survive both planned and unplanned

restarts of your Jenkins master.Pausable: Pipelines can optionally stop and wait for human

input or approval before completing the jobs for which they were built.

Versatile: Pipelines support complex real-world requirements, including the ability to fork or join, loop, and work in parallel with each other.

Extensible: The Pipeline plugin supports custom extensions to its DSL (domain scripting language) and multiple options for integration with other plugins.

* Source: Jenkins.io

Page 12: Pipeline as code - new feature in Jenkins 2

Pipeline prosSupports complex, real-world, CD Pipeline requirements:

pipelines can fork/join, loop, parallel, to name a fewResilient - pipeline executions can survive master restartsPausable - pipelines can pause and wait for human

input/approvalEfficient - pipelines can restart from saved checkpointsVisualized - Pipeline StageView provides status at-a-glance

dashboards including trending

Artifact traceability with fingerprinting - support tracking versions of artifacts using file fingerprinting

Page 13: Pipeline as code - new feature in Jenkins 2

Pipeline vocabularyStep is a single task that is part of build sequenceNode typically enlists help from available executors

on agents to:Schedules the steps contained within it to run by

adding them to the Jenkins build queueCreates a workspace where resource-intensive

processing can occur without negatively impacting your pipeline performance

Stage is a logically distinct part of the execution of any task, with parameters for locking, ordering, and labeling its part of a process relative to other parts of the same process

* Source: Jenkins.io

Page 14: Pipeline as code - new feature in Jenkins 2
Page 15: Pipeline as code - new feature in Jenkins 2
Page 16: Pipeline as code - new feature in Jenkins 2

step([$class: 'ArtifactArchiver', artifacts: '**/target/*.war’, fingerprint: true])

Page 17: Pipeline as code - new feature in Jenkins 2

The JenkinsfileJenkinsfile is a container for pipeline (or other) script,

which details what specific steps are needed to perform a job for which you want to use Jenkins.

Jenkinsfile can be created with text/Groovy editor, or through the configuration page on of Jenkins instance.

Provides DSL steps with most common build tasks(https://jenkins.io/doc/pipeline/steps/)

Can be extended by external shell scripts and import user Groovy scripts

Page 18: Pipeline as code - new feature in Jenkins 2

DSL examplessh, bat - script execution for Unix and Windows systemscm, checkout - checkout source code from VCSreadFile, writeFile, fileExists - file handlingstash, unstash - share workspace results between stageswithEnv, evn.Foo, $BUILD_NUMBER - getting and setting

variablesparallel - set up concurrent tasks

Page 19: Pipeline as code - new feature in Jenkins 2

node('nodeJs') { currentBuild.result = "SUCCESS" try { stage('Checkout') checkout scm stage('Test') env.NODE_ENV = "test" print "Environment will be : ${env.NODE_ENV}" sh 'node -v && npm prune && npm install && npm test' stage('Build Docker') sh './dockerBuild.sh' stage('Deploy') echo 'Push to Repo ssh to web server and tell it to pull new image' sh './dockerPushToRepo.sh' stage('Cleanup') echo 'prune and cleanup' sh 'npm prune && rm node_modules -rf' mail body: 'project build successful', from: '[email protected]', replyTo: '[email protected]', subject: 'project build successful', to: '[email protected]' } catch (err) { currentBuild.result = "FAILURE"

def specificCause = currentBuild.rawBuild.getCause(hudson.model.Cause$UserIdCause) mail body: "project build error is here: ${env.BUILD_URL}" , from: '[email protected]', replyTo: '[email protected]', subject: 'project build failed', to: '[email protected]' throw err }}

Page 20: Pipeline as code - new feature in Jenkins 2

Master-agent architecture

Master node has a list of all configured agentsMaster node starts required Agents and passes build steps

from JenkinsfileAll “hard work” is done by Agents

Http: 8080

Slave: 50000Mas

ter

Agentnodejs

Agentjava

Agentgolang

Slave: 50000

Slave: 50000

Slave: 50000

Page 21: Pipeline as code - new feature in Jenkins 2

Jenkins in Kubernetes

Page 22: Pipeline as code - new feature in Jenkins 2

Jenkins usage across teams

Nana Beta Pi ...

Jenkins agentimages

Source code +

Pipeline libraries

Page 23: Pipeline as code - new feature in Jenkins 2

What makes "Pipeline as a code" valuable for

build/deployments in NewsweaverOrganization folders - enable Jenkins to automatically detect and include any new

repositories within them as resources.

Jenkinsfile as part of source code - A Jenkinsfile is a container for your pipeline (or other) script, which details what specific steps are needed to perform a job for which you want to use Jenkins.

Groovy is good - Jenkinsfiles are written as Groovy scripts which makes them easy to write and add complex logic

Ability to record test results and artifacts

Call agent for help - build tasks can be distributed and assigned to remote nodes.

DRY - Pipeline can reuse build steps stored in SCM which can allow us to avoid code duplication in all branches

Inputs - pipelines can be programed with pauses/human interaction

Concurrent build actions - with a help of Parallel Test Executor we can split steps in parallel parts

Active community - there are plenty code examples, best practices, tutorials on the web

Page 24: Pipeline as code - new feature in Jenkins 2

New & noteworthy featuresBlue Ocean - new UI tailored pipelines as a central theme

to the Jenkins user experienceVisual Pipeline Editor - helps to make things clearer for a

range of users, to help with Workflow adoption

Page 25: Pipeline as code - new feature in Jenkins 2

Blue Ocean (https://jenkins.io/projects/blueocean/)

Page 26: Pipeline as code - new feature in Jenkins 2

Visual Pipeline Editor (https://www.cloudbees.com/blog/introducing-experimental-visual-pipeline-editor)

Page 27: Pipeline as code - new feature in Jenkins 2

Questions