using gitlab ci
TRANSCRIPT
![Page 1: Using GitLab CI](https://reader034.vdocuments.mx/reader034/viewer/2022042520/5882bcfc1a28abb2478b5283/html5/thumbnails/1.jpg)
Using GitLab CI
![Page 2: Using GitLab CI](https://reader034.vdocuments.mx/reader034/viewer/2022042520/5882bcfc1a28abb2478b5283/html5/thumbnails/2.jpg)
“ Continuous Integration is a software development practice wheremembers of a team integrate their work frequently, usually each person
integrates at least daily - leading to multiple integrations per day. ”
- Martin Fowler
![Page 3: Using GitLab CI](https://reader034.vdocuments.mx/reader034/viewer/2022042520/5882bcfc1a28abb2478b5283/html5/thumbnails/3.jpg)
Why GitLab CI?Integration
Fully integrated with GitLabEasy to start
A few lines in yml (YAML) inside of .gitlab-ci.yml and a bit clicksScalable
Concurrent jobs (in parallel), many runners, tagged runnersIsolated test environment
Using Docker containers
![Page 4: Using GitLab CI](https://reader034.vdocuments.mx/reader034/viewer/2022042520/5882bcfc1a28abb2478b5283/html5/thumbnails/4.jpg)
GitLab CI configurationIs done via .gitlab-ci.yml �le:
Example for NodeJS project:
nodejs_run: stage: test script: - npm install - npm test
![Page 5: Using GitLab CI](https://reader034.vdocuments.mx/reader034/viewer/2022042520/5882bcfc1a28abb2478b5283/html5/thumbnails/5.jpg)
How GitLab CI differs fromother CI's?
![Page 6: Using GitLab CI](https://reader034.vdocuments.mx/reader034/viewer/2022042520/5882bcfc1a28abb2478b5283/html5/thumbnails/6.jpg)
RunnersThis is an application that processes builds. It receives commands
from GitLab CI.
It's possible to tag runners so jobs run on runners which can processthem (e.g. di�erent OS)
![Page 7: Using GitLab CI](https://reader034.vdocuments.mx/reader034/viewer/2022042520/5882bcfc1a28abb2478b5283/html5/thumbnails/7.jpg)
ExecutorsShell
LocalyDocker
Inside of Docker containerDocker-SSH
In Docker container communicating over SSHSSH
On remote server using SSH
![Page 8: Using GitLab CI](https://reader034.vdocuments.mx/reader034/viewer/2022042520/5882bcfc1a28abb2478b5283/html5/thumbnails/8.jpg)
StagesUsed to group your jobs in stages to create multiple pipelines
Builds of next stage are run after success
![Page 9: Using GitLab CI](https://reader034.vdocuments.mx/reader034/viewer/2022042520/5882bcfc1a28abb2478b5283/html5/thumbnails/9.jpg)
Repo cleaningBy default, GitLab CI cleans build dir between builds for the sake of
concurrency
But we can preserve builds between builds (Hello, npm andnode_modules !)
![Page 10: Using GitLab CI](https://reader034.vdocuments.mx/reader034/viewer/2022042520/5882bcfc1a28abb2478b5283/html5/thumbnails/10.jpg)
Job concurrencyJobs of the same stage run in parallel
![Page 11: Using GitLab CI](https://reader034.vdocuments.mx/reader034/viewer/2022042520/5882bcfc1a28abb2478b5283/html5/thumbnails/11.jpg)
Start using GitLab CI
![Page 12: Using GitLab CI](https://reader034.vdocuments.mx/reader034/viewer/2022042520/5882bcfc1a28abb2478b5283/html5/thumbnails/12.jpg)
Get runner firstA simple Ubuntu Server VDS can play this role.
Provision it via script:
# Gitlab CI multi runner curl -L https://packages.gitlab.com/install/repositories/runner/gitlab-ci-multi-runner/script.apt-get install -y gitlab-ci-multi-runner
echo 'run "gitlab-ci-multi-runner register"'
Run gitlab-ci-multi-runner register and answer questions.You can �nd your unique registration token under Settings ---> Runners
section.
![Page 13: Using GitLab CI](https://reader034.vdocuments.mx/reader034/viewer/2022042520/5882bcfc1a28abb2478b5283/html5/thumbnails/13.jpg)
Add .gitlab-ci.yml to your repoExample for nodejs:
nodejs_run: stage: test script: - npm install - npm test
![Page 14: Using GitLab CI](https://reader034.vdocuments.mx/reader034/viewer/2022042520/5882bcfc1a28abb2478b5283/html5/thumbnails/14.jpg)
Did you expect anything?This is all!
![Page 15: Using GitLab CI](https://reader034.vdocuments.mx/reader034/viewer/2022042520/5882bcfc1a28abb2478b5283/html5/thumbnails/15.jpg)
Pro tips for usage
![Page 16: Using GitLab CI](https://reader034.vdocuments.mx/reader034/viewer/2022042520/5882bcfc1a28abb2478b5283/html5/thumbnails/16.jpg)
Use cache option in your.gitlab-ci.yml to preserve dirs
or filesThis line will cache all git untracked �les and �les in node_modules dir
cache: untracked: true paths: - node_modules/
![Page 17: Using GitLab CI](https://reader034.vdocuments.mx/reader034/viewer/2022042520/5882bcfc1a28abb2478b5283/html5/thumbnails/17.jpg)
Build skipBuild will be skipped if your commit message contains [ci skip]
![Page 19: Using GitLab CI](https://reader034.vdocuments.mx/reader034/viewer/2022042520/5882bcfc1a28abb2478b5283/html5/thumbnails/19.jpg)
Advanced usage for JS projectsaka "extension"
![Page 20: Using GitLab CI](https://reader034.vdocuments.mx/reader034/viewer/2022042520/5882bcfc1a28abb2478b5283/html5/thumbnails/20.jpg)
How to save build stats for along time?
Bash scripts will save us!
![Page 21: Using GitLab CI](https://reader034.vdocuments.mx/reader034/viewer/2022042520/5882bcfc1a28abb2478b5283/html5/thumbnails/21.jpg)
Private static web server(e.g. nginx)
Use it to store your coverage, static analysis, test cases info for along time
![Page 22: Using GitLab CI](https://reader034.vdocuments.mx/reader034/viewer/2022042520/5882bcfc1a28abb2478b5283/html5/thumbnails/22.jpg)
How to get your infoCollect your test coverage with istanbul (GH: )
(or isparta, GH: )gotwarlost/istanbul
douglasduteil/isparta
Get your mocha test stats in HTML with reporter (GH:)
mochawesomeadamgruber/mochawesome
Catch your static analysis with plato (GH: )es-analysis/plato
![Page 23: Using GitLab CI](https://reader034.vdocuments.mx/reader034/viewer/2022042520/5882bcfc1a28abb2478b5283/html5/thumbnails/23.jpg)
But how to export this info tomy static web server?
Use scriptsomekind bash
Use it like that (line in your .gitlab-ci.yml). npm test should generateistanbul, mocha and plato reports.
my_gitlab_ci_job: script: - npm test ... - /my/path/to/build-export.sh $CI_BUILD_ID $CI_PROJECT_DIR my-project-name
Why not use GitLab CI Web hooks? Because we need access to repository �les
![Page 24: Using GitLab CI](https://reader034.vdocuments.mx/reader034/viewer/2022042520/5882bcfc1a28abb2478b5283/html5/thumbnails/24.jpg)
What about badges?Use to generate SVG image (via bash script), then ...shields.io
... use bash script to save it into public web space
You can use private nginx server, but exclude is from auth for sure:
location ~* ((badge_maintainability\.svg)|(badge_tests\.svg)|(badge_coverage\.svg))$ { auth_basic off; }
Add badge to your README.md. Example for mochawesome:
[![test status](http://path/to/latest/badge_tests.svg)](http://path/to/latest/mochawesome-reports/mochawesome.html
![Page 25: Using GitLab CI](https://reader034.vdocuments.mx/reader034/viewer/2022042520/5882bcfc1a28abb2478b5283/html5/thumbnails/25.jpg)
Questions?
![Page 26: Using GitLab CI](https://reader034.vdocuments.mx/reader034/viewer/2022042520/5882bcfc1a28abb2478b5283/html5/thumbnails/26.jpg)
THE ENDUseful links:
- - - - - My email: - Our organization on GitHub:
Docs for .gitlab-ci.ymlGitLab Runner repository README.mdInstallation on linuxOur custom bash scripts
[email protected]/Lingvokot