Local Gitlab Runner:- If you want to run CICD pipeline from your local shell then we use local runner and it is running on your local mach...
Local Gitlab Runner:- If you want to run CICD pipeline from your local shell then we use local runner and it is running on your local machine. You can refer to a git lab repo and execute the pipeline from your local runner.Here it is not required to validate the account because you are using your local machine for running CICD pipeline
Once Local runner is installed then you need to register it on local machine and need to provide some details like gitlab url,token,tags to connect to a particular project.
Install local gitlab runner on Ubuntu 18.04
Step1: Refer below link for latest way to download and install gitlab runner on your local machine
https://docs.gitlab.com/runner/install/linux-repository.html
Step2:-
curl -L "https://packages.gitlab.com/install/repositories/runner/gitlab-runner/script.deb.sh" | sudo bash
Step3:- Install GitLab runner
sudo apt install docker.io -y
sudo apt-get install gitlab-runner
Step4:- Verify gitabrunner is installed
gitlab-runner -v
Step5: Register gitlab runner to local machine
sudo gitlab-runner register
Enter the GitLab instance URL (for example, https://gitlab.com/):
https://gitlab.com/
Enter the registration token:
Token from your gitlab runner
Enter a description for the runner:
localmachine runner
Enter tags for the runner (comma-separated):
localrunner,localshell
Registering runner... succeeded runner=1T_UqosD
Enter an executor: ssh, virtualbox, docker, docker-ssh, parallels, docker-ssh+machine, kubernetes, custom, shell, docker+machine:
shell
Step6:- To verify that local runner is registered successfully, you need to goto gitlab Project ---> Select Settings---> CICD---> Runner.
When you expand Runner section you will find under "Available Specific Runner" section.
Step7:- Let's update .gitlab-ci.yml file to check that CICD pipeline is running on the local machine or not.
job-to-run:
tags:
- localrunner
- localshell
script:
echo "Hello world"
Step 8:- Once you execute above script then you will find in the log that this pipeline was executed on the local machine.
Step 9: - When you install gitlab runner then a user get create gitlab-runner and it should have sudo permission to run a pipeline.
vi /etc/sudoers
and add below entry after root user info and save your file
gitlab-runner ALL=(ALL) NOPASSWD: ALL
Example:
stages:
- build
- test
- deploy
build:
stage: build
tags:
- localrunner
- localshell
script:
- echo "Build Stage"
test:
stage: test
tags:
- localrunner
- localshell
script:
- echo "Test Stage"
deploy:
stage: deploy
tags:
- localrunner
- localshell
script:
- echo "Deploy Stage"
CICD pipeline with maven junit test
stages:
- build
- test
- deploy
build:
stage: build
tags:
- localrunner
- localshell
script:
- cd /home/vagrant/mvnrepo
- sudo mvn clean package
maven-build:
stage: build
tags:
- localrunner
- localshell
script:
- cd /home/vagrant/mvnrepo
- sudo mvn clean package
artifacts:
paths:
- target/surefire-reports/TEST-*.xml
reports:
junit:
- target/surefire-reports/TEST-*.xml
test:
stage: test
tags:
- localrunner
- localshell
script:
- sudo ls /home/vagrant/mvnrepo/target/*.jar
newtest:
stage: test
tags:
- localrunner
- localshell
script:
- sudo touch /home/vagrant/mvnrepo/passtest
deploy:
stage: deploy
tags:
- localrunner
- localshell
script:
- cd /home/vagrant/mvnrepo
- sudo java -cp target/myproj-1.0-SNAPSHOT.jar com.raman.App
Assignment:-
Write a CICD pipeline that will be executed on your local machine and it will install apache on your local system.
job-to-run:
tags:
- localrunner
- localshell
script:
- sudo apt update
- sudo apt install apache2 -y
To verify that apache is installed on your local system run below command
systemctl status apache2
COMMENTS