Gitlab CI/CD Primer

GitLab has a CI/CD defined in a file called .gitlab-ci.yml

This is a sample for the file

stages:
  - build_stage
  - deploy_stage
build:
  stage: build_stage
  image: node
  script:
    - npm install
  artifacts:
    paths:
      - node_modules
      - package-lock.json
deploy:
  stage: deploy_stage
  image: node
  script:
    - echo "first"
    - node whatever.js

A couple of things:

  • There are a number of stages, they are executed in order
  • Each job is defined with a stage. The default state – if missing – is called test and it is predefined
  • The jobs within a stage you cannot control in which order are executed, that is the reason we use stages
  • You can create your own runner – machine that runs builds
  • image: defines the docker image that is running the show. Default is some ruby stuff, so you want to define a good image unless you can run it with ruby
  • artifacts: usually the products of the build in a stage / job are deleted, however if you want to keep them for the next stage, then you publish them with artifacts
  • There are variables as well; the variables can be referred with $variable_name. There are predefined variables as well, see the docs here. There are hidden variables as well, you defined them in the GUI and then you use them in the script without them appearing in clear.