continuous integration / continuous testing seminary› – hosted jenkins server (jenkins master...

29
Bitte decken Sie die schraffierte Fläche mit einem Bild ab. Please cover the shaded area with a picture. (24,4 x 7,6 cm) Continuous Integration / Continuous Testing Seminary IIC

Upload: others

Post on 26-May-2020

22 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Continuous Integration / Continuous Testing Seminary› – hosted Jenkins Server (Jenkins Master how we call it) inside a docker container › The Jenkins user database is linked

Bitte decken Sie die schraffierte Fläche mit einem Bild ab.Please cover the shaded area with a picture.

(24,4 x 7,6 cm)

Continuous Integration / Continuous TestingSeminary

IIC

Page 2: Continuous Integration / Continuous Testing Seminary› – hosted Jenkins Server (Jenkins Master how we call it) inside a docker container › The Jenkins user database is linked

InternalCoC HMI&Speech

› Java SE Runtime Environment https://www.oracle.com/technetwork/java/javase/downloads/jre8-downloads-2133155.html

› Python 2.7 / 3.x

Requirements

1 November 20182Andrei Teodorescu, Andrei Untu

Page 3: Continuous Integration / Continuous Testing Seminary› – hosted Jenkins Server (Jenkins Master how we call it) inside a docker container › The Jenkins user database is linked

InternalCoC HMI&Speech

› Visit the following site - https://conti-git.gocht.at

› Create your account using your FII email. Only @info.uaic.ro domains are whitelisted

› https://conti-git.gocht.at – hosted GitLab Server inside a docker container

› https://conti-ci.gocht.at – hosted Jenkins Server (Jenkins Master how we call it) inside a docker container

› The Jenkins user database is linked to GitLab’s accounts via OAuthplugin.

Step 1: Create your account

1 November 20183Andrei Teodorescu, Andrei Untu

Page 4: Continuous Integration / Continuous Testing Seminary› – hosted Jenkins Server (Jenkins Master how we call it) inside a docker container › The Jenkins user database is linked

InternalCoC HMI&Speech

› Visit https://conti-git.gocht.at/

› Create a New Project

› Project name: user-name

› Visibility: Private

› Deactivate the Auto DevOps option ☺

› Generate a SSH private key / public pair by running inside a Git Bash Terminal: ssh-keygen

› Extract the public key from the generated path */id_rsa.pub

› Go to your Profile Settings in GitLab web interface -> SSH Key -> Paste the id_rsa.pub file content and save the key

› Now you can clone your repo by following the commands from your project main page

Step 2: Create, set up, clone a GIT repository

1 November 20184Andrei Teodorescu, Andrei Untu

Page 5: Continuous Integration / Continuous Testing Seminary› – hosted Jenkins Server (Jenkins Master how we call it) inside a docker container › The Jenkins user database is linked

InternalCoC HMI&Speech

› Write a dummy Python script with a lot of style errors (no docstring, multiple new lines, no new line at the end of file, don’t respect variable naming convention eg. test_variable)

› Commit the script.

› Push the changes.

Step 2.2: Bullshit Python script

1 November 20185Andrei Teodorescu, Andrei Untu

Page 6: Continuous Integration / Continuous Testing Seminary› – hosted Jenkins Server (Jenkins Master how we call it) inside a docker container › The Jenkins user database is linked

InternalCoC HMI&Speech

› Go to https://conti-ci.gocht.at/computer

› Here is the Jenkins Nodes tab, where you are going to set up your machine as a Jenkins agent (slave).

› All your desired tests will be run inside a continuous pipeline on your specific node.

› The connection will be done on a local side via Java Web Start application (creates a SSH connection directly with the Jenkins Master by validating a secret token). The user logged in into that machine who establish the connection will be used as the host runner for each Jenkins build on that machine.

› How to add your node:

Step 3: Set up your machine as a Jenkins Node

1 November 20186Andrei Teodorescu, Andrei Untu

Page 7: Continuous Integration / Continuous Testing Seminary› – hosted Jenkins Server (Jenkins Master how we call it) inside a docker container › The Jenkins user database is linked

InternalCoC HMI&Speech 1 November 2018

7Andrei Teodorescu, Andrei Untu

Page 8: Continuous Integration / Continuous Testing Seminary› – hosted Jenkins Server (Jenkins Master how we call it) inside a docker container › The Jenkins user database is linked

InternalCoC HMI&Speech 1 November 2018

8Andrei Teodorescu, Andrei Untu

Page 9: Continuous Integration / Continuous Testing Seminary› – hosted Jenkins Server (Jenkins Master how we call it) inside a docker container › The Jenkins user database is linked

InternalCoC HMI&Speech

› If you set up the node configuration via Java Web Start the following page should appear:

1 November 20189Andrei Teodorescu, Andrei Untu

Download the agent.jar by clicking on the link ☺

Page 10: Continuous Integration / Continuous Testing Seminary› – hosted Jenkins Server (Jenkins Master how we call it) inside a docker container › The Jenkins user database is linked

InternalCoC HMI&Speech

› Now we will switch to your OS CLI and run the specified command

1 November 201810Andrei Teodorescu, Andrei Untu

Page 11: Continuous Integration / Continuous Testing Seminary› – hosted Jenkins Server (Jenkins Master how we call it) inside a docker container › The Jenkins user database is linked

InternalCoC HMI&Speech

› Visit https://conti-ci.gocht.at/credentials/store/system/domain/_/

› Add Credentials

› Kind: Username with password

› Username: Your GitLab username

› Password: your GitLab password

› ID: leave blank

› Description: Username

Step 4: Create new Jenkins credentials

1 November 201811Andrei Teodorescu, Andrei Untu

Page 12: Continuous Integration / Continuous Testing Seminary› – hosted Jenkins Server (Jenkins Master how we call it) inside a docker container › The Jenkins user database is linked

InternalCoC HMI&Speech

� Access the Jenkins master page https://conti-ci.gocht.at/

� Switch to your LabX view

� Create your Jenkins Pipeline by clicking on the New Item icon.

Step 5: Create & Configure a Jenkins Pipeline

1 November 201812Andrei Teodorescu, Andrei Untu

Page 13: Continuous Integration / Continuous Testing Seminary› – hosted Jenkins Server (Jenkins Master how we call it) inside a docker container › The Jenkins user database is linked

InternalCoC HMI&Speech 1 November 2018

13Andrei Teodorescu, Andrei Untu

Page 14: Continuous Integration / Continuous Testing Seminary› – hosted Jenkins Server (Jenkins Master how we call it) inside a docker container › The Jenkins user database is linked

InternalCoC HMI&Speech

› Skip directly to pipeline configuration

1 November 201814Andrei Teodorescu, Andrei Untu

Page 15: Continuous Integration / Continuous Testing Seminary› – hosted Jenkins Server (Jenkins Master how we call it) inside a docker container › The Jenkins user database is linked

InternalCoC HMI&Speech

› In the pipeline config page, Enable project-based security for full disclosure over your pipeline and select the last option and leave the matrix empty

Optional: My pipe security

1 November 201815Andrei Teodorescu, Andrei Untu

Page 16: Continuous Integration / Continuous Testing Seminary› – hosted Jenkins Server (Jenkins Master how we call it) inside a docker container › The Jenkins user database is linked

InternalCoC HMI&Speech

› Write a groovy script by following the next template:

› https://conti-git.gocht.at/snippets/2

› Commit the groovy script inside your project’s GIT repository

› Push the commit

› Note: Usually having a Jenkins as the CI Service, a separate repository is used for holding the groovy scripts + CI Scripts.

Step 6: Create the Pipeline’s groovy script

1 November 201816Andrei Teodorescu, Andrei Untu

Page 17: Continuous Integration / Continuous Testing Seminary› – hosted Jenkins Server (Jenkins Master how we call it) inside a docker container › The Jenkins user database is linked

InternalCoC HMI&Speech

› Select your pipeline from your Lab View

› Build Now – Enjoy the automagically act happening.

› Also congrats for your +2 Points

Step 7: Run your Pipeline

1 November 201817Andrei Teodorescu, Andrei Untu

Page 18: Continuous Integration / Continuous Testing Seminary› – hosted Jenkins Server (Jenkins Master how we call it) inside a docker container › The Jenkins user database is linked

InternalCoC HMI&Speech

› Manually triggering a Job only for the latest commit into the master branch is far from the Continuous Integration meaning. Well there might be jobs that are only to be manually started by a user (Integrator / Configuration Manager / responsible DevOps Engineer) only in some specific cases, but what we covered is not fit for a main integration pipeline

› So shame on us everybody gets:

› -2 POINTS

* just kidding the next part is for an additional 1 point

** not the optional 1 point

It’s that enough?

1 November 201818Andrei Teodorescu, Andrei Untu

Page 19: Continuous Integration / Continuous Testing Seminary› – hosted Jenkins Server (Jenkins Master how we call it) inside a docker container › The Jenkins user database is linked

InternalCoC HMI&Speech

› Basic concept:

› User to GitLab to Jenkins:

› The user pushes to GitLab repo remotes/origin/master a commit

› The project is directly integrated with a webhook from a specific Jenkins project for which only some (or all, who cares) events are chosen to be sent

› Data in JSON format is sent over via the Jenkins project webhook with various information about the commit to be tested / integrated / checked / reported etc.

› The Jenkins job is configured to accept only some (or all, who cares) events by interpreting that JSON data.

› The job can now start and build that specific reference and test within the stages created inside the groovy script.

› But the failure / success status will be only visible from a Jenkins side perspective

Step 8: Enable automatic triggers for the pipeline

1 November 201819Andrei Teodorescu, Andrei Untu

Page 20: Continuous Integration / Continuous Testing Seminary› – hosted Jenkins Server (Jenkins Master how we call it) inside a docker container › The Jenkins user database is linked

InternalCoC HMI&Speech

› Basic concept:

› Jenkins to GitLab (to User):

› Once the pipeline is triggered, it should be able to poll the exact revision from the GitLab server via SCM. And should be able to query between all references.

› If the Pipeline it’s triggered automatically by GitLab, it should send back values like stages status and overall pipeline status and the status of Integrate or not that specific change

› This is done by having one Admin account or at least on developer’s account for that project depending on what the pipeline can and will do. (If it’s intended to merge the changes if they succeed, this operation will need an Admin rank account for the project). The GitLab account’s API Token is stored in Jenkins and via that protocol the statuses are posted in GitLab.

1 November 201820Andrei Teodorescu, Andrei Untu

Page 21: Continuous Integration / Continuous Testing Seminary› – hosted Jenkins Server (Jenkins Master how we call it) inside a docker container › The Jenkins user database is linked

InternalCoC HMI&Speech

› Configure Pipeline > Build Triggers > Something with GitLab

› Check only Push Events, because I had no time to look over the Opened Merge Request Events (ongoing commit reviews)

Step 8.1: Activate GitLab trigger in Jenkins Pipeli ne

1 November 201821Andrei Teodorescu, Andrei Untu

Page 22: Continuous Integration / Continuous Testing Seminary› – hosted Jenkins Server (Jenkins Master how we call it) inside a docker container › The Jenkins user database is linked

InternalCoC HMI&Speech

› Copy the webhook which is marked at the precedent step.

› Go to your GitLab project > Settings >Integrations

› Paste the webhook, select only push events and add the webhook

› To test if the connection works, scroll down: and select from the dropdown the Push Event:

Step 8.2: Set up JSON data send to the webhook

1 November 201822Andrei Teodorescu, Andrei Untu

Page 23: Continuous Integration / Continuous Testing Seminary› – hosted Jenkins Server (Jenkins Master how we call it) inside a docker container › The Jenkins user database is linked

InternalCoC HMI&Speech

› Enable the parametrization of this pipeline, via this option we will can run manually the pipeline to check things on the last snapshot, as the default value will be: master

› Also via this parameter we will fetch the tested snapshot from JSON data.

Step 8.2: SCM Polling

1 November 201823Andrei Teodorescu, Andrei Untu

Page 24: Continuous Integration / Continuous Testing Seminary› – hosted Jenkins Server (Jenkins Master how we call it) inside a docker container › The Jenkins user database is linked

InternalCoC HMI&Speech

› Refspec: +refs/heads/*:refs/remotes/origin/* +refs/merge-requests/*/head:refs/remotes/origin/merge-requests/*

1 November 201824Andrei Teodorescu, Andrei Untu

Page 25: Continuous Integration / Continuous Testing Seminary› – hosted Jenkins Server (Jenkins Master how we call it) inside a docker container › The Jenkins user database is linked

InternalCoC HMI&Speech

› If you “protected” your pipeline add Build rights for Anonymous Users, so GitLab can trigger builds.

› Only one GitLab Connection: There is one account set up with it’s API Token on Jenkins which will post pipelines statuses in GitLab (which is an Admin account = general read / write access)

Step 8.3: Additional Settings / Info

1 November 201825Andrei Teodorescu, Andrei Untu

Page 26: Continuous Integration / Continuous Testing Seminary› – hosted Jenkins Server (Jenkins Master how we call it) inside a docker container › The Jenkins user database is linked

InternalCoC HMI&Speech

› Via the following template:

› https://conti-git.gocht.at/snippets/4

Step 8.4: Adapt groovy script

1 November 201826Andrei Teodorescu, Andrei Untu

Page 27: Continuous Integration / Continuous Testing Seminary› – hosted Jenkins Server (Jenkins Master how we call it) inside a docker container › The Jenkins user database is linked

InternalCoC HMI&Speech

› Commit anything and watch your pipeline automagically starting and posting results to GitLab

› + 1 more point

Step 9:

1 November 201827Andrei Teodorescu, Andrei Untu

Page 28: Continuous Integration / Continuous Testing Seminary› – hosted Jenkins Server (Jenkins Master how we call it) inside a docker container › The Jenkins user database is linked

InternalCoC HMI&Speech

› Create another pipeline, which groovy script is placed in the same repository.

› This pipeline is triggered by the first pipeline if it succeeds.

› It has 3 stages: Prerequisites, Python – Check PyLint, Finalize Verification

› In the PyLint stage. It runs another code checker for python called PyLint and spits all the information in one txt which is then published as a report attached to the pipeline in HTML format.

› The pipeline fails if the PyLint discovers any Warnings / Errors, but it publishes every time the HTML Report

› (Adds information to the commit that triggered the first pipeline) Don’t know if it works, might skip this

› It’s more of a research task, the actual codding is really lightweight.

› +1 More point if you finish the task

Optional +1 Point

1 November 201828Andrei Teodorescu, Andrei Untu

Page 29: Continuous Integration / Continuous Testing Seminary› – hosted Jenkins Server (Jenkins Master how we call it) inside a docker container › The Jenkins user database is linked

1 November 201829Andrei Teodorescu, Andrei Untu