Automate Your CI - CD Pipeline With GitLab Runner (SSH) On Ubuntu
Automate Your CI - CD Pipeline With GitLab Runner (SSH) On Ubuntu
Runner(SSH) on Ubuntu
Buildbot Technologies Private Limited + Follow
Introduction:
GitLab Runner is an open-source tool that allows you to run your GitLab CI/CD jobs. It
can be configured to run on various platforms, such as Linux, macOS, and Windows,
and it supports different executors like Docker, Kubernetes, and Shell.
To register a GitLab Runner, you can use the GitLab-runner register command, which
will
4
prompt you for the necessary information, such as the GitLab instance URL, a
registration token, and a description. You can also specify these values as command-
line arguments orLike
environment variables. Comment Share
Once registered, you can manage your GitLab Runners using various commands, such
as GitLab-runner list to list all registered runners, Gitlab-runner unregisters to
unregister a specific runner, and Gitlab-runner reset-token to reset a runner's token.
To run a job using GitLab Runner, you can use the GitLab-Runner run command, which
will start the GitLab Runner service and execute all registered runners. Alternatively,
you can use the GitLab-runner run-single command to run a single job using a specific
runner.
GitLab Runner also supports debug mode, which can be useful when troubleshooting
issues. To run a command in debug mode, you can use the --debug flag.
Finally, GitLab Runner can be configured to use different executors, such as Docker or
Shell, and you can specify the Docker image to use for the Docker executor. Here is an
example of running a job using the Docker executor with the GitLab-runner run-single
command
Prerequisites:
https://docs.gitlab.com/runner/install/linux-manually.html#using-binary-file
Below
4 are instructions to install Gitlab-runner
1. Simply download
Likeone of the binaries for your system:
Comment
Command: sudo curl -L --output /usr/local/bin/gitlab-runner "https://
1. Permission to execute:
Recommended by LinkedIn
Like Comment
Automating Application Start on Ubuntu with systemd
Praveen Kumar · 6 months ago
1. Generate ssh-keys using root and copy the id_rsa.pub key to the GitLab account
4
Step 5. Clone the code in the GitLab project locally using SSH
Like Comment
We need to clone the repository using SSH
Navigate to Repo>Project>Settings>CI/CD>Runner
We are choosing the operating system Linux we need to specify the tag and then
create the runner
Register runner:
Step 1 Copy and paste the following command into your command line to register the runner.
4
$ gitlab-runner register
--url https://gitlab.com
Like Comment
--token glrt-CWQLfY4a4YeBofk-uoci
Step 2: Choose an executor when prompted by the command line. Executors run builds in
different environments. Which one to select?
Step 3 (optional)
$ gitlab-runner run
After creating the runner we can verify the runner status is online
Like Comment
Note: We are using ssh instead of https so we need to configure env variables in the
/home/gitlab-runner/.gitlab-runner/config.toml
Env variables:
concurrent = 1
check_interval = 0
connection_max_age = "15m0s"
shutdown_timeout = 0
[session_server]
session_timeout = 1800
[[runners]]
name = "ssh"
url = "https://gitlab.com"
4
id = 33217256
Like Comment
token = "glrt-QpdzCxasfbyxpq3Vnsc2"
token_obtained_at = 2024-02-28T11:37:24Z
token_expires_at = 0001-01-01T00:00:00Z
executor = "ssh"
environment = ["GIT_STRATEGY=none"]
pre_build_script = '''
mkdir -p "${CI_PROJECT_DIR}"
cd "${CI_PROJECT_DIR}"
git init
'''
[runners.cache]
MaxUploadedArchiveSize = 0
[runners.ssh]
user = "root"
password = "Password@123"
port = "22"
4
identity_file = "/root/.ssh/id_rsa"Step 7: Then after doing the changes restart the
GitLab-runner
Like Comment
Command: gitlab-runner restart
In the .gitlab-ci.yml file create a pipeline as follows, after committing the changes we
can verify the job is successfully installed (java, maven, docker, and docker-compose)
stages:
- Orchestrate
job1:
stage: Orchestrate
script:
- cd /opt
- wget http://<ip address>/path of tar.gz
- tar -zxvf test.tar.gz --directory=/opt
- cd /opt/scripts
- ./install_all.sh
tags:
- ssh-test
Step 9: Result
I hope
4 this article has provided you with valuable insights into the topic at hand. Whether you're a
beginner or an experienced professional, there's always something new to learn and discover in
the world. By sharing my knowledge and experience with you, I hope to have sparked your
Like Comment
curiosity and inspired you to explore further. Thank you for taking the time to read this article,
and I look forward to hearing your thoughts and feedback.
Written By,
DevOps Team
DevOps
How do you troubleshoot docker alpine vs ubuntu compatibility issues with other tools or
frameworks?
Operating Systems
How can you write Bash scripts that are compatible across different Operating Systems?
Software Development
4
How do you automate repetitive tasks using Linux command line scripts?
Like Comment
System Administration
Software Development
What are the key differences between Linux command line and GUI usage?
Show more
Mastering Git and GitHub: A Comprehensive Cheat Sheet for Linux Users
Sanket Bhalke · 1y
Show more
Explore topics
Sales
4
Marketing
Like Comment
Business Administration
HR Management
Content Management
Engineering
Soft Skills
See All
© 2024 About
Language
Like Comment