First GitLab CI - NodeJS example
Select Project -> Set up CI
Add a .gitlab-ci.yml file to the root directory of your repository, and configure your GitLab project to use a Runner, then each commit or push, triggers your CI pipeline.
This is a .gitlab-ci.yml example.
image: node:8
cache:
paths:
- node_modules/
stages:
- test
test_job1:
stage: test
script:
- npm install
- node ./index.js
tags:
- docker
You can see pipeline job is started when you push your code. But it is pending.
Configuring a Runner: Kubernetes executor
Set URL and token on your ConfigMap YAML fileConfigMap:
apiVersion: v1
kind: ConfigMap
metadata:
name: gitlab-runner
namespace: gitlab-registry
data:
config.toml: |
concurrent = 4
[[runners]]
name = "Kubernetes Runner"
url = "*********"
token = "*********"
executor = "kubernetes"
[runners.kubernetes]
namespace = "gitlab-registry"
image = "node:8"
Kubernetes auto-deployments
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: gitlab-runner
namespace: gitlab-registry
spec:
replicas: 1
selector:
matchLabels:
name: gitlab-runner
template:
metadata:
labels:
name: gitlab-runner
spec:
containers:
- args:
- run
image: gitlab/gitlab-runner:latest
imagePullPolicy: Always
name: gitlab-runner
volumeMounts:
- mountPath: /etc/gitlab-runner
name: config
- mountPath: /etc/ssl/certs
name: cacerts
readOnly: true
restartPolicy: Always
volumes:
- configMap:
name: gitlab-runner
name: config
- name: cacerts
persistentVolumeClaim:
claimName: k8s-cer-pvc
Issue: We get the logs from officials YAML file.
Starting multi-runner from /etc/gitlab-runner/config.toml ... builds=0
Running in system-mode.
Configuration loaded builds=0
Metrics server disabled
ERROR: Checking for jobs... forbidden runner=ziFnjP1b
ERROR: Checking for jobs... forbidden runner=ziFnjP1b
ERROR: Checking for jobs... forbidden runner=ziFnjP1b
ERROR: Runner http://**********/ci************* is not healthy and will be disabled!
How to fix?
It is fixed by https://gitlab.com/gitlab-org/gitlab-runner/issues/2002. That is modified deployment yaml and remove ConfigMap.
apiVersion: apps/v1beta1
kind: Deployment
metadata:
name: gitlab-runner
namespace: gitlab-registry
labels:
app: gitlab-runner
spec:
replicas: 3
template:
metadata:
labels:
app: gitlab-runner
spec:
initContainers:
- name: init-runner
image: gitlab/gitlab-runner:latest
args:
- register
env:
- name: RUNNER_TAG_LIST
value: "docker"
- name: CI_SERVER_URL
value: "https://gitlab.com/ci"
- name: REGISTER_NON_INTERACTIVE
value: "true"
- name: REGISTRATION_TOKEN
value: "***********"
- name: RUNNER_EXECUTOR
value: kubernetes
- name: RUNNER_REQUEST_CONCURRENCY
value: "4"
# Must use privileged mode for docker-in-docker
- name: KUBERNETES_PRIVILEGED
value: "true"
# More variables as needed (see below)
volumeMounts:
- mountPath: /etc/gitlab-runner
name: config
- mountPath: /etc/ssl/certs
name: cacerts
readOnly: true
- name: init-runner-volume
image: alpine
command: ["sh", "-c"]
# Append hostpath mount to configuration because there is no env variable for it
# https://gitlab.com/gitlab-org/gitlab-ci-multi-runner/issues/2578
args:
- |
cat <<EOF >> /etc/gitlab-runner/config.toml
[[runners.kubernetes.volumes.host_path]]
name = "docker-sock"
mount_path = "/var/run/docker.sock"
host_path = "/var/run/docker.sock"
EOF
volumeMounts:
- mountPath: /etc/gitlab-runner
name: config
containers:
- name: runner
image: gitlab/gitlab-runner:latest
args:
- run
volumeMounts:
- mountPath: /etc/gitlab-runner
name: config
- mountPath: /etc/ssl/certs
name: cacerts
readOnly: true
volumes:
- name: cacerts
persistentVolumeClaim:
claimName: k8s-cer-pvc
- name: config
emptyDir: {}
You will see the runner on your setting page