ENV variables
https://docs.gitlab.com/ee/ci/variables/predefined_variables.html
Build and push Docker Images with Gitlab CI
# .gitlab-ci.yml
build:
stage: build
image: docker:19.03.1
services:
- docker:dind
before_script:
- echo -n $CI_JOB_TOKEN | docker login -u gitlab-ci-token --password-stdin $CI_REGISTRY
script:
- docker build --pull -t "$CI_REGISTRY_IMAGE" .
- docker push "$CI_REGISTRY_IMAGE"
tags:
- docker
# Dockerfile
FROM alpine:3.10
RUN apk add --no-cache nginx
Reuse commands across Gitlab jobs
https://jsramblings.com/three-ways-to-reuse-commands-across-gitlab-jobs/
.prepare_step:
before_script:
- echo 'prepare'
build:
extends:
- .prepare_step
script:
- echo 'build'
test:
extends:
- .prepare_step
script:
- echo 'test'
Checkout additional repository witht SSH key
https://stackoverflow.com/questions/44363537/gitlab-ci-ssh-permission-denied-publickey-password
https://docs.gitlab.com/ee/ci/ssh_keys/
script:
- mkdir -p ~/.ssh
- echo "$SSH_PRIVATE_KEY" | tr -d '\r' > ~/.ssh/id_rsa
- chmod 700 ~/.ssh/id_rsaCheckout additional repository with token
script:
- 'git clone --branch master git@git.i.example.com:foo/bar.git $CI_BUILDS_DIR/deploy'
Links
https://about.gitlab.com/2016/05/23/gitlab-container-registry/