TMF2014 CI-CD Workshop Michael Palotas

84
TEST MANAGERS FORUM 2014 SYDNEY, AUSTRALIA CONTINUOUS INTEGRATION CONTINUOUS DELIVERY 1

description

A very big thank you to Michael Palotas from Grid Fusion & eBay International for taking the time and effort to travel across the globe to present at the Australian Test Managers Forum 2014. If you would like any information on TMF please email [email protected]

Transcript of TMF2014 CI-CD Workshop Michael Palotas

Page 1: TMF2014 CI-CD Workshop Michael Palotas

TEST MANAGERS FORUM 2014 SYDNEY, AUSTRALIA CONTINUOUS INTEGRATION CONTINUOUS DELIVERY

1

Page 2: TMF2014 CI-CD Workshop Michael Palotas

2

WHO AM I? Gridfusion Software Solutions Contact: Michael Palotas Gerbiweg 2 8853 Lachen SWITZERLAND Tel.: +41 79 6690708 Email: [email protected]

Head of Productivity & Test Engineering, eBay

Founder / Principal Consultant Gridfusion Software Solutions

Page 3: TMF2014 CI-CD Workshop Michael Palotas

SETTING THE STAGE

Tell me about yourself J

What are your expectations for today?

3

Page 4: TMF2014 CI-CD Workshop Michael Palotas

Your setup

How do you build software?

4

Page 5: TMF2014 CI-CD Workshop Michael Palotas

WHAT IS SO SPECIAL ABOUT AGILE?

5

Page 6: TMF2014 CI-CD Workshop Michael Palotas

WHY CI/CD?

6

Page 7: TMF2014 CI-CD Workshop Michael Palotas

WHAT IS IMPORTANT IN AGILE?

7

Page 8: TMF2014 CI-CD Workshop Michael Palotas

Agile

=

Release working software anytime

8

Page 9: TMF2014 CI-CD Workshop Michael Palotas

Traditional waterfall model / tools do not support “build and deploy anytime”

9

Page 10: TMF2014 CI-CD Workshop Michael Palotas

WHAT IS CI / CD?

CI and CD

=

Automated Build?

Automated Tests?

Automated Quality?

Automated Deployment?

Automated Feedback?

10

Page 11: TMF2014 CI-CD Workshop Michael Palotas

WHY CI / CD

Deliver value to the business more frequently

Better Quality

Early Bugs

Bug Prevention instead of late detection

Fast & frequent feedback

11

Page 12: TMF2014 CI-CD Workshop Michael Palotas

WHY CI / CD

Automated frequent builds

Automated frequent tests

Automated frequent code quality metrics

(Hopefully) Fewer bugs

Fast feedback

12

Page 13: TMF2014 CI-CD Workshop Michael Palotas

WITHOUT CI

Slow / long release cycles

Late testing

Waterfall (WaterScrum)

Bugs

Slow feedback

Complex integration

13

Page 14: TMF2014 CI-CD Workshop Michael Palotas

CORE PRINCIPLES

Every build could be a release

Everything should be automated

Stable and trustworthy automated tests

Build pipelines

14

Page 15: TMF2014 CI-CD Workshop Michael Palotas

RELEASING IN THE OLD WORLD

15

Coding

Deploy to

QA

QA

Deploy to Production

Production Smoke Tests

Bug Bashes

Page 16: TMF2014 CI-CD Workshop Michael Palotas

CI / CD - CORE WORKFLOW

16

Compile

Unit Test

Deploy to QA

Acceptance tests

Deploy to Production

Production Smoke Tests

Code Quality

Page 17: TMF2014 CI-CD Workshop Michael Palotas

THE MAIN TASKS

Automated build

Automated code quality

Automated testing

Automated deployment

17

Page 18: TMF2014 CI-CD Workshop Michael Palotas

18

Wakaleo.com

Page 19: TMF2014 CI-CD Workshop Michael Palotas

CAN YOU MEASURE AUTOMATED CODE QUALITY? DOES THAT MAKE SENSE?

19

Page 20: TMF2014 CI-CD Workshop Michael Palotas

AUTOMATED CODE QUALITY?

Sonar gives you information on:

-  Lines of code

-  % of comments

-  Duplications

-  Complexity

-  Rules compliance

-  Unit test coverage

-  Unit test success rate

-  Unit test duration

-  Hotspots

20

Page 21: TMF2014 CI-CD Workshop Michael Palotas

CAN / SHOULD YOU AUTOMATE EVERYTHING?

21

Page 22: TMF2014 CI-CD Workshop Michael Palotas

WHAT SHOULD YOU AUTOMATE?

22

Page 23: TMF2014 CI-CD Workshop Michael Palotas

WHAT ARE BARRIERS TO CI / CD?

23

Page 24: TMF2014 CI-CD Workshop Michael Palotas

WHAT IS CONTIUOUS INTEGRATION?

24

Continuous integration (CI) is the practice, in software engineering, of merging all developer working copies with a shared mainline several times a day. It was first named and proposed as part of extreme programming (XP). Its main aim is to prevent integration problems, referred to as "integration hell" in early descriptions of XP. CI can be seen as an intensification of practices of periodic integration advocated by earlier published methods of incremental and iterative software development, such as the Booch method. CI isn't universally accepted as an improvement over frequent integration, so it is important to distinguish between the two as there is disagreement about the virtues of each.

Page 25: TMF2014 CI-CD Workshop Michael Palotas

WHAT IS CONTINUOUS DELIVERY?

25

Continuous Delivery (CD) is a design practice used in software development to automate and improve the process of software delivery. Techniques such as automated testing, continuous integration and continuous deployment allow software to be developed to a high standard and easily packaged and deployed to test environments, resulting in the ability to rapidly, reliably and repeatedly push out enhancements and bug fixes to customers at low risk and with minimal manual overhead. The technique was one of the assumptions of extreme programming but at an enterprise level has developed into a discipline of its own, with job descriptions for roles such as "buildmaster" calling for CD skills as mandatory.

Page 26: TMF2014 CI-CD Workshop Michael Palotas

THE MANAGEMENT / ORGANIZATIONAL ASPECT

What are the changes for developers and testers?

What needs to be changed in the organization to enable them to implement CI / CD?

What role has management in creating a devops culture?

26

Page 27: TMF2014 CI-CD Workshop Michael Palotas

OUR TOOLS

Version Control System GIT Build Tool MAVEN Unit Test Framework JUNIT / TESTNG End To End Test Framework SELENIUM Build Server / Deployment JENKINS

27

Page 28: TMF2014 CI-CD Workshop Michael Palotas

Branching & Merging

Small and Fast

Distributed

Data Assurance

Staging Area

Free and Open Source

VERSION CONTROL: GIT

28

http://git-scm.com/about/

Page 29: TMF2014 CI-CD Workshop Michael Palotas

GIT: BRANCHING & MERGING

29

Git-scm.com

Page 30: TMF2014 CI-CD Workshop Michael Palotas

GIT: SMALL & FAST

30

Git-scm.com

Page 31: TMF2014 CI-CD Workshop Michael Palotas

GIT: THE REST

Distributed

Data Assurance

Staging Area

Free & Open Source

31

Page 32: TMF2014 CI-CD Workshop Michael Palotas

GIT

Distributed / local

Download: http://git-scm.com/

Initialize directory: git init

Status: git status

Add files and directories to git: git add file1 dir2

Commit: git commit –am “commit message”

32

Page 33: TMF2014 CI-CD Workshop Michael Palotas

SHARE YOUR CODE - GITHUB

Create repository on Github: https://github.com

Create remote: git remote add origin https://…

Push code to Github: git push origin master

Tag your code: git tag –a v0.1 –m “initial version”

Push tag to Github: git push origin v0.1

33

Page 34: TMF2014 CI-CD Workshop Michael Palotas

GITHUB

34

Page 35: TMF2014 CI-CD Workshop Michael Palotas

CONNECT GIT AND GITHUB

35

Silverpeas.org

Page 36: TMF2014 CI-CD Workshop Michael Palotas

MAVEN

36

Apache Maven is a software project management and comprehension tool. Based on the concept of a project object model (POM), Maven can manage a project's build, reporting and documentation from a central piece of information.

http://maven.apache.org/guides/getting-started/maven-in-five-minutes.html

Page 37: TMF2014 CI-CD Workshop Michael Palotas

POM.XML

The pom.xml file is the core of a project's configuration in Maven. It is a single

configuration file that contains the majority of information required to build a project in just

the way you want.

37

Page 38: TMF2014 CI-CD Workshop Michael Palotas

POM.XML

38

Page 39: TMF2014 CI-CD Workshop Michael Palotas

MAVEN TARGETS

validate: validate the project is correct and all necessary information is available

compile: compile the source code of the project

test: test the compiled source code using a suitable unit testing framework. These tests should not require the code be packaged or deployed

package: take the compiled code and package it in its distributable format, such as a JAR.

integration-test: process and deploy the package if necessary into an environment where integration tests can be run

verify: run any checks to verify the package is valid and meets quality criteria

install: install the package into the local repository, for use as a dependency in other projects locally

deploy: done in an integration or release environment, copies the final package to the remote repository for sharing with other developers and projects.

clean: cleans up artifacts created by prior builds

39

Page 40: TMF2014 CI-CD Workshop Michael Palotas

EXAMPLES

mvn clean

mvn compile

mvn test

40

Page 41: TMF2014 CI-CD Workshop Michael Palotas

CONTINUOUS INTEGRATION - JENKINS

Download at http://jenkins-ci.org/

41

Page 42: TMF2014 CI-CD Workshop Michael Palotas

RECAP

WHAT DO WE EXPECT

THE CI SYSTEM TO DO?

42

Page 43: TMF2014 CI-CD Workshop Michael Palotas

43

Page 44: TMF2014 CI-CD Workshop Michael Palotas

A JENKINS JOB

44

Page 45: TMF2014 CI-CD Workshop Michael Palotas

WHAT JENKINS DOES

Jenkins checks out the workspace from Github

Builds and runs tests locally according to POM

Runs maven targets according to POM description

45

Page 46: TMF2014 CI-CD Workshop Michael Palotas

A SIMPLE BUILD JOB

46

Page 47: TMF2014 CI-CD Workshop Michael Palotas

A SIMPLE BUILD JOB

1.  Add / change some code

2.  Push to Github repository

3.  Let Jenkins pick up the change

4.  Perform mvn clean compile targets

5.  Perform mvn test target (unit tests only)

47

Page 48: TMF2014 CI-CD Workshop Michael Palotas

TEST AUTOMATION

Unit Tests

E2E Tests

Manual Tests

Integration Tests

Page 49: TMF2014 CI-CD Workshop Michael Palotas

WHAT IS SELENIUM?

Selenium automates browsers

that’s it

Page 50: TMF2014 CI-CD Workshop Michael Palotas

E2E / UAT AUTOMATION WITH SELENIUM

50

CLIENT

SERVER JSON Wire Protocol

BROWSER

Page 51: TMF2014 CI-CD Workshop Michael Palotas

SELENIUM

JSON WIRE PROTOCOL

Client

Java

C#

Ruby

Python

Server Driver

Driver

Driver

Page 52: TMF2014 CI-CD Workshop Michael Palotas

CLIENT

Is seen as „Selenium“ by the users

Generates HTTP requests which are received by the server

Is called by the test framework or the CI server

Supported languages: Java, C#, Python, Ruby, Perl, PHP,

JS

Page 53: TMF2014 CI-CD Workshop Michael Palotas

SERVER

Receives HTTP requests

Start and teardown of browser

Translates requests into browser specific commands

Communicates back to the client

Page 54: TMF2014 CI-CD Workshop Michael Palotas

SELENIUM GRID Sequential Execution

Test 1 Test 2 Test …

Test 4500

Execution Time

Test 3

Parallel Execution

Test Test Test

Execution Time

Test

Test Test Test Test

Test Test Test Test

Par

alle

l Exe

cutio

n

Par

alle

l Exe

cutio

n

Page 55: TMF2014 CI-CD Workshop Michael Palotas

SELENIUM GRID

Page 56: TMF2014 CI-CD Workshop Michael Palotas

TEST INFRASTRUCTURE

AUT

DB

API

Browsers Mobiles

CLIENT

Page 57: TMF2014 CI-CD Workshop Michael Palotas

57

Page 58: TMF2014 CI-CD Workshop Michael Palotas

A SIMPLE SELENIUM TEST

58

Page 59: TMF2014 CI-CD Workshop Michael Palotas

59

Page 60: TMF2014 CI-CD Workshop Michael Palotas

LET’S BUILD A BUILD / DEPLOYMENT PIPELINE

60

Page 61: TMF2014 CI-CD Workshop Michael Palotas

THE MASTER JOB

61

Unit Test

Deploy to QA

Acceptance tests

Deploy to Production

Production Smoke Tests

Code Coverage

Page 62: TMF2014 CI-CD Workshop Michael Palotas

THE APPLICATION

62

Page 63: TMF2014 CI-CD Workshop Michael Palotas

63

Page 64: TMF2014 CI-CD Workshop Michael Palotas

CONNECT CODE WITH GITHUB

64

Page 65: TMF2014 CI-CD Workshop Michael Palotas

UNIT TESTS

65

Page 66: TMF2014 CI-CD Workshop Michael Palotas

RUN UNIT TESTS LOCALLY

Run from eclipse

Run from maven

66

Page 67: TMF2014 CI-CD Workshop Michael Palotas

67

Page 68: TMF2014 CI-CD Workshop Michael Palotas

UNIT TEST COVERAGE - COBERTURA

68

Page 69: TMF2014 CI-CD Workshop Michael Palotas

69

Page 70: TMF2014 CI-CD Workshop Michael Palotas

SONAR: CODE ANALYSIS / CODE QUALITY

70

Page 71: TMF2014 CI-CD Workshop Michael Palotas

71

Page 72: TMF2014 CI-CD Workshop Michael Palotas

WE ARE READY FOR THE NEXT STEP

ADD CI JENKINS

SET UP JENKINS JOBS

-  Master Job

-  Run unit tests

-  Deploy to QA

-  Run E2E tests

-  Deploy to PROD

-  Run PROD smoke tests

72

Page 73: TMF2014 CI-CD Workshop Michael Palotas

MASTER JOB

73

Page 74: TMF2014 CI-CD Workshop Michael Palotas

JOB: UNIT TESTS (1)

74

Page 75: TMF2014 CI-CD Workshop Michael Palotas

JOB: UNIT TEST (2)

75

Page 76: TMF2014 CI-CD Workshop Michael Palotas

JOB: DEPLOY TO QA

76

Page 77: TMF2014 CI-CD Workshop Michael Palotas

JOB: INTEGRATION TESTS

77

Page 78: TMF2014 CI-CD Workshop Michael Palotas

JOB: DEPLOY TO PRODUCTION

78

Page 79: TMF2014 CI-CD Workshop Michael Palotas

JOB: PRODUCTION SMOKE TESTS

79

Page 80: TMF2014 CI-CD Workshop Michael Palotas

JOB: SONAR

80

Page 81: TMF2014 CI-CD Workshop Michael Palotas

JOB: COBERTURA

81

Page 82: TMF2014 CI-CD Workshop Michael Palotas

PIPELINE: HAPPY PATH

82

Page 83: TMF2014 CI-CD Workshop Michael Palotas

PIPELINE: UNHAPPY PATH

83

Page 84: TMF2014 CI-CD Workshop Michael Palotas

THANK YOU!

84