GitLab - A full DevOps tool

mail

.gitlab-ci.yml

Sample .gitlab-ci.yml (source) :

stages:							all the stages this pipeline has, listed in execution order
  - build
  - test
  - deploy

job1:
  stage: build						which stage this job runs in
  script:
    - echo "This job compiles code."

job2:
  stage: test						which stage this job runs in
  script:
    - echo "This job tests the compiled code. It runs when the build stage completes."

job3:							when a job defines no stage, it defaults to test
  script:
    - echo "This job also runs in the test stage."

job4:
  stage: deploy						which stage this job runs in
  script:
    - echo "This job deploys the code. It runs when the test stage completes."
  environment: production
When a pipeline is initiated, GitLab checks out the code from the specified branch, including the .gitlab-ci.yml file. In other words : when you run a pipeline from a specific branch, it uses the .gitlab-ci.yml file from that branch (source).
mail

Data is missing in the API results

Situation

Objects (projects, whatever) I am sure they DO exist are not listed when querying the API.

Details

This is because the API results are paginated.

Solution

You'll have to specify extra parameters in the query :
myToken='ZsyqJk1Rz6ZQ3EjyyEQL'; serverName='gitlab.myCompany.tld'; serverIp='10.2.0.97'; curl -s -k --proxy "http://10.2.0.20:3128" --header "PRIVATE-TOKEN: $myToken" --header "hostname: $serverName" "https://$serverIp/api/v4/projects?per_page=50&page=1" | jq -r '.[] | .id,.name'
mail

GitLab glossary

.gitlab-ci.yml
  • YAML file holding GitLab CI / CD pipelines configuration
jobs
  • are made of a list of commands and define what to do (compile code, run tests, )
  • are written in .gitlab-ci.yml
  • are executed by runners
    • jobs in the same stage can execute in parallel if they run on different runners
    • if you have only one runner, jobs can run in parallel if the runner's concurrent setting is > 1
  • names :
    • can be up to 255 characters long
    • should be unique (not mandatory, but can cause problems)
  • There are some special job types :
personal access token
ID to authenticate with the GitLab API. Get yours.
pipeline
  • top-level component of CI / CD
  • Pipelines have
    1. jobs
    2. stages
rules (rules)
  • are conditions to include/exclude jobs to/from pipelines (i.e. run those jobs or not)
  • are evaluated
    • when the pipeline is created
    • in order
    • when a match is found
      • the corresponding job is included to / excluded from the pipeline
      • no more rules are checked
      if none of the rules matches, the job is not added to the pipeline
runner (https://docs.gitlab.com/ci/runners/, https://docs.gitlab.com/runner/)
  • isolated + ephemeral VM / cloud instance that executes jobs
  • each runner, as it becomes available, continually sends requests to the GitLab instance, asking to be assigned jobs
stage (vegastack.com, medium.com)
  • define when to run jobs : conditional execution of groups of tasks. For example :
    1. compile code
    2. if ok, run tests
  • stages / jobs :
    • jobs in the same stage run in parallel
    • jobs in the next stage run after the jobs from the previous stage complete successfully
  • stages defaults to
    .pre
    build
    test
    deploy
    .post