Advanced Continuous Integration

48
Advanced Continuous Integration Ein Projektbericht

description

http://www.opitz-consulting.com/go/3-4-894 Die Literatur sagt, dass „Broken Builds“ auf jeden Fall zu vermeiden sind, weil andere Entwickler sich durch die fehlerhaften Änderungen ihren Entwicklungsbereich kaputt machen und dann nicht arbeiten können. Die Solution Architects unserer IT-Beratung, Stefan Scheidt und Richard Attermeyer, zeigten in ihrem Vortrag am 10.Oktober 2013 bei der gearconf 2013 in Düsseldorf, dass „broken Builds“ nicht das Problem sind. Im Rahmen der Präsentation zeigten die Referenten, wie man durch geeignete Branching- und CI-Strategien stets eine stabilen Branch sicherstellen kann. Veranschaulicht wurde das Ganze durch eine konkrete Umsetzung mittels Git / GitLab und Jenkins. -- Über uns: Als führender Projektspezialist für ganzheitliche IT-Lösungen tragen wir zur Wertsteigerung der Organisationen unserer Kunden bei und bringen IT und Business in Einklang. Mit OPITZ CONSULTING als zuverlässigem Partner können sich unsere Kunden auf ihr Kerngeschäft konzentrieren und ihre Wettbewerbsvorteile nachhaltig absichern und ausbauen. Über unsere IT-Beratung: http://www.opitz-consulting.com/go/3-8-10 Unser Leistungsangebot: http://www.opitz-consulting.com/go/3-8-874 Karriere bei OPITZ CONSULTING: http://www.opitz-consulting.com/go/3-8-5

Transcript of Advanced Continuous Integration

Page 1: Advanced Continuous Integration

AdvancedContinuous Integration

Ein Projektbericht

Page 2: Advanced Continuous Integration

Wer sind wir?

[email protected]: attermr

GitHub: rattermeyer

[email protected]: stefanscheidtGitHub: stefanscheidt

Page 3: Advanced Continuous Integration

© OPITZ CONSULTING GmbH 2011 Seite 3Mobile JavaScript-Web-Apps

MissionWir entwickeln gemeinsam mit allen Branchen Lösungen, die dazu führen, dass sich diese Organisationen besser entwickeln als ihr Wettbewerb.

Unsere Dienstleistung erfolgt partnerschaftlich und ist auf eine langjährige Zusammenarbeit angelegt.

LeistungsangebotBusiness IT AlignmentBusiness Information ManagementBusiness Process ManagementAnwendungsentwicklungSOA und System-Integration IT-Infrastruktur-Management

MärkteBranchenübergreifendÜber 600 Kunden

29%Industrie / Versorger /

Telekommunikation

29%Handel / Logistik / Dienstleistungen

42% Öffentliche Auftraggeber / Banken und Versicherungen / Vereine und Verbände

EckdatenGründung 1990 400 Mitarbeiter9 Standorte

Page 4: Advanced Continuous Integration

Wer sind Sie?

Page 5: Advanced Continuous Integration

Die Herausforderung

Page 6: Advanced Continuous Integration

Also mussten wir uns beeilen ...

Page 7: Advanced Continuous Integration

Aber manchmal waren wir zu schnell ...

Page 8: Advanced Continuous Integration

Abhilfe durchContinuous Integration

Page 9: Advanced Continuous Integration

Continuous Integration Process

1. […] wait for it to finish […] work with the rest of the teamto make it green before you check in

2. …

3. Run the build script and tests on your development machine […]

4. […]

5. Wait for your CI tool to run the build with your changes

6. […]

7. If the build passes, rejoice and move on to your next task

Jez Humble, David Farley, Continuous Delivery

Page 10: Advanced Continuous Integration

Continuous Integration Process

1. […] wait for it to finish […] work with the rest of the teamto make it green before you check in

2. …

3. Run the build script and tests on your development machine […]

4. […]

5. Wait for your CI tool to run the build with your changes

6. […]

7. If the build passes, rejoice and move on to your next task

Jez Humble, David Farley, Continuous Delivery

Page 11: Advanced Continuous Integration

Continuous Integration Process

1. […] wait for it to finish […] work with the rest of the teamto make it green before you check in

2. …

3. Run the build script and tests on your development machine […]

4. […]

5. Wait for your CI tool to run the build with your changes

6. […]

7. If the build passes, rejoice and move on to your next task

Jez Humble, David Farley, Continuous Delivery

Page 12: Advanced Continuous Integration

Continuous Integration Process

1. […] wait for it to finish […] work with the rest of the teamto make it green before you check in

2. …

3. Run the build script and tests on your development machine […]

4. […]

5. Wait for your CI tool to run the build with your changes

6. […]

7. If the build passes, rejoice and move on to your next task

Jez Humble, David Farley, Continuous Delivery

Page 13: Advanced Continuous Integration

Continuous Integration Process

1. […] wait for it to finish […] work with the rest of the teamto make it green before you check in

2. …

3. Run the build script and tests on your development machine […]

4. […]

5. Wait for your CI tool to run the build with your changes

6. […]

7. If the build passes, rejoice and move on to your next task

Jez Humble, David Farley, Continuous Delivery

Page 14: Advanced Continuous Integration

Continuous Integration Process

1. […] wait for it to finish […] work with the rest of the teamto make it green before you check in

2. …

3. Run the build script and tests on your development machine […]

4. […]

5. Wait for your CI tool to run the build with your changes

6. […]

7. If the build passes, rejoice and move on to your next task

Jez Humble, David Farley, Continuous Delivery

"If everybody on the team follows these simple steps every time they commit any change, you will know that your software works on any box with the same configuration as the CI box at all times."

Page 15: Advanced Continuous Integration

CI System soll für mich arbeiten

- nicht umgekehrt!

WTF!Etwas stimmt nicht!

Keiner bezahlt mich dafür zu warten, um sicher zu

gehen, dass alle Tests immer noch grün sind.

Ich will einchecken wann ich will!

Ich will den meinen Build kaputt gehen

lassen, wann ich will!

Page 16: Advanced Continuous Integration

Wie kann ein Prozess aussehen, bei dem ein

kaputter Build kein „stop-the-line“ bedeutet?

Page 17: Advanced Continuous Integration

We want TeamCity‘s Feature back:

Pre-Tested Commits

Page 18: Advanced Continuous Integration

Breaking the build is no crime!

Page 19: Advanced Continuous Integration

Voraussetzung:Einfaches Branching und Merging

Page 20: Advanced Continuous Integration

development

rat/for-development

mis/for-development

mho/for-development

Ein Branch pro Entwickler

Entwicklungsbranch, in den integriert werden soll: Branch pro Entwicklermit Namenskonvention

Entwicklerbranches werden von development abgespaltenEntwicklerbranches sind „privat“Entwicklerbranches werden vom CI-System wieder in development integriert

Page 21: Advanced Continuous Integration

Variation: Feature Branches

Page 22: Advanced Continuous Integration

Wichtige Punkte(nicht-offensichtlich)

Abgleich immer über den Integration-BranchSelbst wenn mehrere Entwickler

am gleichen Feature arbeiten

Kein direkter Merge eines Feature-Branchin den lokalen Working-Branch

Außer man weiß, was man tut ...

Page 23: Advanced Continuous Integration

Vorteile

Ich kann unabhängig arbeitenund zentral sichern

Das CI-System führt die zeit- und resourcenaufwändigen Tests für mich durch

… während ich schon weiter arbeiten kann

Page 24: Advanced Continuous Integration

Vorteile

Der Integration-Branch ist immer grünDurch einen Merge hole ich nur „guten“ Code

Ich kann ziemlich sicher sein, dass der Code auch nach dem Merge gebaut werden kann

Page 25: Advanced Continuous Integration

Vorteile

Als Entwickler verbringe ich nichtunnötig Zeit damit Dinge zu fixen,die andere kaputt gemacht haben

Page 26: Advanced Continuous Integration

Eine Umsetzung

+

Page 27: Advanced Continuous Integration

Jenkins Git Plugin 1/3

Überwache Entwicklerbranches

Page 28: Advanced Continuous Integration

Jenkins Git Plugin 2/3

Merge Entwickler-Branch auf Development-Branch

Page 29: Advanced Continuous Integration

Jenkins Git Plugin 3/3

Push merged Development-Branch

zurück, wenn Build erfolgreich

Page 30: Advanced Continuous Integration

Entwicklungsprozess aus Entwicklersicht

origin/development

git fetchgit merge orgin/development

git add / commit

git push origin rat/for-development

1. Merge2. Build3. Push

Page 31: Advanced Continuous Integration

Demo ...

Page 32: Advanced Continuous Integration

Kriterien für „Gut-Genug“

Müssen nur die „echten“ Unit Tests laufen?

Oder müssen alle Tests laufen?(Unit-, Integrations- und Systemtests)

Lange Feedback-ZyklenHohe Latenz, bis Kollegen

von Änderungen profitieren können

Page 33: Advanced Continuous Integration

Kriterien für „Gut-Genug“

Oder will ich sogar nochein echtes Code-Review?

Nicht allein durch Jenkins möglichZum Beispiel Gerrit als Review-Tool

Code-Reviews für jeden Commitbei jungen Projekt sehr aufwändig

Page 34: Advanced Continuous Integration

Kriterien für „Gut-Genug“

Lesson Learned:

Die Kriterien ändern sich im Projektverlauf

Page 35: Advanced Continuous Integration

Kriterien für „Gut-Genug“

Anfangs: Alle Tests müssen grün seinHäufig große Änderungen

Integrationstests hatten deutlich mehrAussagekraft als Unit Tests

Später: Unit-Tests müssen grün seinWeniger „breaking changes“

Integrationstestfehler mit 4h Zeitverzugentdecken reicht aus

Page 36: Advanced Continuous Integration

Die Konsequenz ...

Page 37: Advanced Continuous Integration

Umkehr der Verantwortung

An: Meine Kollegen

Hallo,

habe meinen Code eingechecked, bin dann mal in Urlaub. BTW: CI Server ist jetzt rot und meldet 15 Testfehler. Müsste sich jemand mal anschauen…

Bis in 2 Wochen

früher:

Page 38: Advanced Continuous Integration

Umkehr der Verantwortung

An: Meine Kollegen

Hallo,

wollte euch meinen Code noch vor dem Urlaub zu Verfügung stellen. Hat mich leider noch 2 Stunden gekostet, die 15 Testfehler zu beseitigen. Jenkins hat den Code jetzt aber erfolgreich gemerged. Alles grün!

Bis in 2 Wochen.

jetzt:

Page 39: Advanced Continuous Integration

Dies und das ...

Page 40: Advanced Continuous Integration

Durchsetzen der Konvention: Protected Branches

Page 41: Advanced Continuous Integration

Beispiel: GitLab

Protected branches are designed to preventpush for all except masters. This ability allows:• keep stable branches secured• forced code review before merge to

protected branches

Page 42: Advanced Continuous Integration

Pull statt fetch/merge[branch "rat/for-development"] remote = origin merge = refs/heads/rat/for-development

.git/config

Page 43: Advanced Continuous Integration

Pull statt fetch/merge[branch "rat/for-development"] remote = origin merge = refs/heads/rat/for-development

[branch "rat/for-development"] remote = origin merge = refs/heads/development

.git/config

.git/config

Page 44: Advanced Continuous Integration

Pull statt fetch/merge[branch "rat/for-development"] remote = origin merge = refs/heads/rat/for-development

[branch "rat/for-development"] remote = origin merge = refs/heads/development

$ git pull

From git-e.opitz-consulting.int:cel/oc-days-git-2013 d40fefe..86878f9 development -> origin/developmentAlready up-to-date.

.git/config

.git/config

Page 45: Advanced Continuous Integration

Gotchas

Polling durch Jenkings undmehrere Commits in Zeitfenster

Besser:post-receive Hook

Web Hooks in Stash und GitLab

Page 46: Advanced Continuous Integration

Gotchas

„Git hat meine Änderungen verschlampt“

==

„Ich habe nicht gemerkt, dass mein Commit nicht sauber gemerged werden konnte“

Page 47: Advanced Continuous Integration

Noch Fragen?