Part I -
I’m learning Gitlab Runner and how them works on CI implementation.
GitLab Runner is an application that works with GitLab CI to run jobs in a pipeline, they are written in GO
Summary the task I will do:
- Install Gitlab-runner as container(podman).
- Runner registration.
- Enter the GitLab instance URL
- registration token.
- runner description.
- tags.
- Select an executor.
- Create a gitlab-ci.yml
Install runner:
- Create the Volume:
podman volume create gitlab-runner-config
Pull and start the container by register command, then we will prompt the data need for register the runner into the project.
podman run --rm -it -v gitlab-runner-config:/etc/gitlab-runner gitlab/gitlab-runner:alpine register
Example (I select shell executor):
02:34:24 jose@fedora .gitlab-runner → podman run --rm -it -v gitlab-runner-config:/etc/gitlab-runner gitlab/gitlab-runner:alpine register
Runtime platform arch=amd64 os=linux pid=2 revision=8925d9a0 version=14.1.0
Running in system-mode.
Enter the GitLab instance URL (for example, https://gitlab.com/):
https://gitlab.com/
Enter the registration token:
«your runner token»
Enter a description for the runner:
[70d0a9e9edc9]: podman
Enter tags for the runner (comma-separated):
«»
Registering runner... succeeded runner=BdvMUJxJ
Enter an executor: ssh, docker+machine, docker-ssh+machine, kubernetes, docker-ssh, docker, parallels, shell, virtualbox, custom:
shell
Runner registered successfully. Feel free to start it, but if it's running already the config should be automatically reloaded!
Here you can frin the token from your project .
testing the Gitlab-runner works:
podman run --rm -t -i gitlab/gitlab-runner --help
For testing purpose we can run the container as below:
podman run --name gitlab-runner -v gitlab-runner-config:/etc/gitlab-runner gitlab/gitlab-runner:alpine
- Create a gitlab-ci.yml
we will use the runner on shell executor mode in order to run a shell script.
- gitlab-ci.yml file:
stages:
- test
ScriptBuild:
stage: test
script:
- bash script.sh
- bash file:
#!/bin/bash
echo "starting script"
cat text.txt | wc -l
note: you must create both files into root folder of your project
remember: “you should install GitLab Runner on a machine that’s separate from the one that hosts the GitLab instance for security and performance reasons”
Further info: https://docs.gitlab.com/runner/ Best practices: https://docs.gitlab.com/runner/best_practice/index.html