In this tutorial you will see how you can create you gitlab-ci.yml file in your repository and execute jobs on gitlab pipelines.
- In AWS, create an instance and choose the
Amazon Linux 2 AMImachine. - Create a new key pair with the name similar like
gitlab-runner. Isn't needed to be the same, just a name so you can identfy the purpose.- The key pair type can be
ED25519
- The key pair type can be
- Login to the server machine with
ssh ec2-user@...via terminal; - Update dependencies:
sudo yum -y update- Install Git:
sudo yum install -y gitInstall Docker:
sudo amazon-linux-extras install -y docker- Add the ec2-user user to the docker group:
sudo usermod -aG docker ec2-user- Ensure the Docker daemon starts automatically:
sudo systemctl enable docker- Restart your EC2 instance:
sudo rebootYou will desconnect to the server. Please reconnect!
- After reconnect, make sure docker was connected automatically. To check that execute this command:
docker run hello-worldYou will see something like this:
- Download the GitLab Runner installation package:
curl -LJO "https://gitlab-runner-downloads.s3.amazonaws.com/latest/rpm/gitlab-runner_amd64.rpm"- Install the GitLab Runner:
sudo rpm -i gitlab-runner_amd64.rpmAt the end of the installation, you will see something like this:
- In group or project repository disable shared runners:
Settings > CI/CD > Runners
- Register the GitLab Runner:
sudo gitlab-runner registerNow, you must answer some questions. The URL and registration token, you can find them by in Settings > CI/CD > Runners:
The other questions, please check here to fill the same answers:
- Check if gitlab runner is running properly:
sudo gitlab-runner statusOutput:
gitlab-runner: Service is runningIn Settings > CI/CD > Runners, check if Available runners is displaying:
Now, we can add our first gitlab-ci.yml configuration.
Below we have a quickly sample script to put in the root folder of our repository project and we can check if it's everything works.
stages:
- build
- test
- deploy
Build:
stage: build
script:
- echo "Building is running."
Test:
stage: test
script:
- echo "Testing is running."
Deploy:
stage: deploy
script:
- echo "Deploying is running." We need to give docker some priviliges to avoid future issues. Go to the
- Login to the server machine with
ssh ec2-user@...via terminal. - Edit the
config.tomlfile:
sudo vim /etc/gitlab-runner/config.tomlInside of config.toml file please replace:
privileged = falseto:
privileged = true- Restart gitlab runner and check the status if it's everything works:
sudo gitlab-runner restart
sudo gitlab-runner statusOutput should be:
gitlab-runner: Service is runningThat's it guys.
I hope this helps you to unterstand how this works and you can finally build your first pipeline in your project.
You can follow all steps on this YouTube Video as well.
Good luck!





