Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Using GitLab CI

7,928 views

Published on

Our experience in using GitLab CI on NodeJS project
Link to reveal.js presentation: https://github.com/Lingvokot/using-gitlab-ci

Published in: Software

Using GitLab CI

  1. 1. Using GitLab CI
  2. 2. “ Continuous Integration is a software development practice where members of a team integrate their work frequently, usually each person integrates at least daily - leading to multiple integrations per day. ” - Martin Fowler
  3. 3. Why GitLab CI? Integration Fully integrated with GitLab Easy to start A few lines in yml (YAML) inside of .gitlab-ci.yml and a bit clicks Scalable Concurrent jobs (in parallel), many runners, tagged runners Isolated test environment Using Docker containers
  4. 4. GitLab CI configuration Is done via .gitlab-ci.yml le: Example for NodeJS project: nodejs_run: stage: test script: - npm install - npm test
  5. 5. How GitLab CI differs from other CI's?
  6. 6. Runners This 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 process them (e.g. di erent OS)
  7. 7. Executors Shell Localy Docker Inside of Docker container Docker-SSH In Docker container communicating over SSH SSH On remote server using SSH
  8. 8. Stages Used to group your jobs in stages to create multiple pipelines Builds of next stage are run after success
  9. 9. Repo cleaning By default, GitLab CI cleans build dir between builds for the sake of concurrency But we can preserve builds between builds (Hello, npm and node_modules !)
  10. 10. Job concurrency Jobs of the same stage run in parallel
  11. 11. Start using GitLab CI
  12. 12. Get runner first A 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.
  13. 13. Add .gitlab-ci.yml to your repo Example for nodejs: nodejs_run: stage: test script: - npm install - npm test
  14. 14. Did you expect anything? This is all!
  15. 15. Pro tips for usage
  16. 16. Use cache option in your .gitlab-ci.yml to preserve dirs or files This line will cache all git untracked les and les in node_modules dir cache: untracked: true paths: - node_modules/
  17. 17. Build skip Build will be skipped if your commit message contains [ci skip]
  18. 18. Validate your .gitlab-ci.yml Using lint: gitlab.com/ci/lint
  19. 19. Advanced usage for JS projects aka "extension"
  20. 20. How to save build stats for a long time? Bash scripts will save us!
  21. 21. Private static web server (e.g. nginx) Use it to store your coverage, static analysis, test cases info for a long time
  22. 22. How to get your info Collect your test coverage with istanbul (GH: ) (or isparta, GH: ) gotwarlost/istanbul douglasduteil/isparta Get your mocha test stats in HTML with reporter (GH: ) mochawesome adamgruber/mochawesome Catch your static analysis with plato (GH: )es-analysis/plato
  23. 23. But how to export this info to my static web server? Use scriptsomekind bash Use it like that (line in your .gitlab-ci.yml). npm test should generate istanbul, 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
  24. 24. 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
  25. 25. Questions?
  26. 26. THE END Useful links: - - - - - My email: - Our organization on GitHub: Docs for .gitlab-ci.yml GitLab Runner repository README.md Installation on linux Our custom bash scripts maxim.sysoev@lingvokot.com github.com/Lingvokot

×