How to set up Gitlab CI/CD pipeline + Gitlab Runner

Photo by Pankaj Patel on Unsplash

Pre-requisite

Let’s understand gitlab pipeline — .gitlab-ci.yml

image: docker:latest
services:
- docker:dind
variables:
DOCKER_DRIVER: overlay
SPRING_PROFILES_ACTIVE: gitlab-ci
stages:
- build-microservice1
- build-microservice2
- package-microservice1
- package-microservice2

build-microservice1:
image: maven:3-jdk-8
stage: build-microservice1
script: "mvn clean install -f microservice1/pom.xml"
artifacts:
paths:
- microservice1/target/*.jar
build-microservice2:
image: maven:3-jdk-8
stage: build-microservice2
script: "mvn clean install -f microservice2/pom.xml"
artifacts:
paths:
- microservice2/target/*.jar

package-microservice1:
stage: package-microservice1
script:
- docker build -t ${CI_REGISTRY}/${CI_PROJECT_PATH}/gitlab/microservice1:latest microservice1/
- docker login -u gitlab-ci-token -p $CI_BUILD_TOKEN registry.gitlab.com
- docker push ${CI_REGISTRY}/${CI_PROJECT_PATH}/gitlab/microservice1:latest
package-microservice2:
stage: package-microservice2
script:
- docker build -t ${CI_REGISTRY}/${CI_PROJECT_PATH}/gitlab/microservice2:latest microservice2/
- docker login -u gitlab-ci-token -p $CI_BUILD_TOKEN registry.gitlab.com
- docker push ${CI_REGISTRY}/${CI_PROJECT_PATH}/gitlab/microservice2:latest

Lets run the pipeline

Lets Check the Package/Docker Image

How to run CI/CD pipeline on On-Premise GitLab

Father || Coder || Engineer || Learner || Reader || Writer