version your build process as you version your code

33
Version your build process as you version your code Vincent Latombe @Vlatombe

Upload: vincent-latombe

Post on 13-Apr-2017

335 views

Category:

Engineering


1 download

TRANSCRIPT

Page 1: Version your build process as you version your code

Version your build process as you version your codeVincent Latombe

@Vlatombe

Page 2: Version your build process as you version your code

Footer

#jenkinsconf

The speaker

Software Engineer at CloudBees

Heavy Jenkins user since 2010 Maintainer of the Clearcase plugin Contributes to core, git and literate

2

Page 3: Version your build process as you version your code

Footer

#jenkinsconf

Agenda

What is Literate ? Literate in Practice Literate in real life Under the hood

3

Page 4: Version your build process as you version your code

#jenkinsconf

What is Literate?

Page 5: Version your build process as you version your code

Footer

#jenkinsconf

Literate Programming

• Introduced by Donald Knuth in 1983

• Explain program logic using natural language with snippets of code and macros

5

Page 6: Version your build process as you version your code

Footer

#jenkinsconf

Literate Builds

• Applies Literate paradigm to builds • Describes the build steps in a marker file

or simply in README.md • Build definition stored in the same SCM

as the code it is building

6

Page 7: Version your build process as you version your code

Footer

#jenkinsconf

Literate Builds

• Marker file within the SCM • May contain the build

definition • Fallback to README.md if

empty

7

Page 8: Version your build process as you version your code

Footer

#jenkinsconf

Markdown Cheatsheet

A section ========= This is text inside section. And `this is inline code`.

some code

8

Page 9: Version your build process as you version your code

Footer

#jenkinsconf

Hello world example

Hello world literate project ============================

Build -----

Let's say hello

echo "Hello world"

9

Page 10: Version your build process as you version your code

Footer

#jenkinsconf

Ant example

Environments =========== Notice how we specify the environment to build with by providing Jenkins node labels or tool installer names in code snippet sections attached to bullet points in an "environment" section?

* `ant-1.8`, `java-1.7`

Build =====

ant clean dist

10

Page 11: Version your build process as you version your code

Footer

#jenkinsconf

Matrix build? No problem

Complex project ===============

Environments ===========

We have two different environments that the build must be run on:

* `linux`, `gcc-4.2`, `ant-1.8`, `maven-3.0.5`, `java-1.7` * `windows`, `vs-pro-2012`, `ant-1.8`, `maven-3.0.5`, `java-1.7`

11

Page 12: Version your build process as you version your code

Footer

#jenkinsconf

Build commands per environment

Build =====

We have two different sets of build instructions, one for building with visual studio and the other for building with GCC

* On `gcc-4.2`, we start by building the native code

./configure make

* On `vs-pro-2012`, we have a batch file to do the native steps

call build-native.bat

12

Page 13: Version your build process as you version your code

Footer

#jenkinsconf

Additional tasks

• Defined in the marker file • Enabled per branch using the job configuration • Lightweight promotion

– Self-promotion – Manual promotion (with optional parameters)

13

Page 14: Version your build process as you version your code

Footer

#jenkinsconf

Extensions (1/2) : job configuration

• Things you want as a Jenkins admin – Timestamp logs – Discard old builds – Clean up workspace before build – Notification to GitHub/Stash

– Use Branch Properties

14

Page 15: Version your build process as you version your code

Footer

#jenkinsconf

Extensions (2/2) : in SCM

• Things you leave up to the developer – Files stored in SCM under .jenkins folder – Basic: <extensionName>.xml, contains the config snippet

found in config.xml – Implement Agent to expose higher-level configuration files

– location of test results – coverage threshold

15

Page 16: Version your build process as you version your code

#jenkinsconf

Literate in practice

Page 17: Version your build process as you version your code

Footer

#jenkinsconf

Installation

• Set up experimental update center • http://updates.jenkins-ci.org/experimental/update-center.json • Check for updates

• Install Literate plugin and dependencies • Restart if needed

17

Page 18: Version your build process as you version your code

Footer

#jenkinsconf

DEMO TIME !

• https://github.com/Vlatombe/literate-sample

18

Page 19: Version your build process as you version your code

#jenkinsconf

Literate in real life

Page 20: Version your build process as you version your code

Footer

#jenkinsconf

Context

• About 3000 developers • Commercial products

– ~1000 Java/JEE – ~2000 C++

• For internal tooling, add – Python – Ruby – Perl

20

Page 21: Version your build process as you version your code

Footer

#jenkinsconf

It’s about control!

• Fully open • Locked down • Balanced

– Template-based solutions: only defined attributes can be customized – Literate: commands can be customized, post-build actions can be whitelisted

21

Page 22: Version your build process as you version your code

Footer

#jenkinsconf

Infrastructure

22

Stash Jenkins

❑ 1.Enable CI

2.Creates

3.Index branches

4.Parses marker

Literate Multi-branch project

Literate branch project

Project/Repository

Literate env. project

Literate env. project

5.Update build status

Page 23: Version your build process as you version your code

Footer

#jenkinsconf

YAML Parser

• Markdown considered too textual, too much space for syntax errors, even if using README.md was tempting

• YAML fanboys • New parser was easy to implement thanks to existing Literate

architecture

23

Page 24: Version your build process as you version your code

Footer

#jenkinsconf

Markdown vs YAML

Environments ============

* `windows`, `java-1.6` * `linux`, `java-1.7` Build =====

mvn –B clean verify

24

environments: - [windows, java-1.6] - [linux, java-1.7] build: mvn –B clean verify

YAMLMarkdown

versus

Page 25: Version your build process as you version your code

#jenkinsconf

Under the hood

Page 26: Version your build process as you version your code

Footer

#jenkinsconf

Architecture

26

Literate-plugin

Literate-apiBranch-api

Scm-api

Page 27: Version your build process as you version your code

Footer

#jenkinsconf

Literate-api

• Builds a Project Model from a text file • Doesn’t depend on Jenkins • Pluggable model builders

– Markdown – YAML

27

Page 28: Version your build process as you version your code

Footer

#jenkinsconf

Scm-api

• jenkins.scm.api.SCMSource : provider for hudson.scm.SCM instances

• Able to comprehend multiple heads on a SCM

– Git branches – Github pull requests – Gerrit reviews

28

Page 29: Version your build process as you version your code

Footer

#jenkinsconf

Branch-api

• Toolkit to handle multi-branch – Dead branch policy – Untrusted branches – Build retention – Throttling

• Foundation for – Multi-branch freestyle project – Multi-branch template project – Multi-branch workflow (see demo by @tyvole at 1pm)

29

Page 30: Version your build process as you version your code

Footer

#jenkinsconf

Literate-plugin

• Extension points – LiterateBranchProperty : decorate branch and environments with anything

(buildwrapper, properties…) – Agent : Builds Publisher instances from files in the SCM.

30

Page 31: Version your build process as you version your code

Footer

#jenkinsconf

What’s next?

• Integration with multi-branch workflow – Use the literate descriptor to feed a workflow – Branch sources for GitHub, Bitbucket, Stash pull requests – Additional plugins compatibility

• Essentially the same problem as with workflow, without the necessary investment behind

31

Page 32: Version your build process as you version your code

Footer

#jenkinsconf

Takeout

• Drive your build process from your SCM • Use a description markup, independant from Jenkins • Proper multi-branch support!

• Give it a try !

32

Page 33: Version your build process as you version your code

#jenkinsconf

Footer

Thanks to our Sponsors!

33