[en] Testing Gitlab CI config locally post


Gitlab CI server is driven by Docker. It means that everything what is happening on the server is ran under docker containers. So you don't need to push anything to the server to test configuration changes.

Step by step tutorial

Please follow by the tutorial and if you meet any issues just comment the article.

Step 1 - Gitlab CI configuration

# .gitlab-ci.yml
# Use yml anchors, to keep jobs DRY, cf.: https://docs.gitlab.com/ee/ci/yaml/#anchors
.build_template_go: &build_definition_go
  image: golang:1.11
    - linux
    - docker
    - ./bin/setup.sh
    - ./bin/build.sh
    - ./bin/test.sh
  stage: build

  <<: *build_definition_go
    key: ${CI_JOB_NAME}
      - ${GOPATH}

  <<: *build_definition_go
    key: ${CI_JOB_NAME}
      - ${GOPATH}

Step 2 - Gitlab Runner

gitlab-runner is a project that allows to run builds locally (somewhere outside gitlab-ci servers) and send the results back to Gitlab.

Apart from that there is a way to run the CI build locally without sending results. This approach we gonna use.

Please visit a gitlab-runner project page and install gitlab-runner binary.

# https://docs.gitlab.com/runner/install/osx.html

sudo curl --output /usr/local/bin/gitlab-runner https://gitlab-runner-downloads.s3.amazonaws.com/latest/binaries/gitlab-runner-darwin-amd64

sudo chmod +x /usr/local/bin/gitlab-runner

You don't need to register CI runner to the Gitlab project.

Step 3 - Execute the build locally

gitlab-runner exec docker sample-api gitlab-runner exec docker sample-worker

Kategorie: devops

Tagi: go, dev, gitlab, gitlab-runner, gitlabci, golang, ci, continuous, integration