Hi everyone,
I have a gitlab instance who is self-hosted on a Cent-OS 7 VM.
I have also created a repository and a docker runner configured on the same machine.
I have created a pipeline but the problem is that when I push my local changes to the gitlab repository, the pipeline isn’t executed.
The only way the pipeline is executed is when i commit from the pipeline editor in Gitlab.
I have tried several solutions, such as creating a rule to execute the pipeline if there is a commit but that doesn’t change anything.
I should point out that the problem occurs even with a simple basic pipeline, so i’dont think the pipeline is the problem.
At this stage, i have no idea why this is happening. Am i missing something ?
This is my .gitlab-ci.yml :
stages:
- build
- deploy
docker-build:
stage: build
# Use the official docker image
image: docker:stable
services:
# Use docker-dind let the gitlab-runner to execute his own docker command (and then isolate it from host)
- name: docker:20-dind
alias: docker
command: [ "--tls=false" ]
variables:
# Docker runner configuration (include host address, driver and not need of TLS)
DOCKER_HOST : tcp://docker:2375
DOCKER_DRIVER : overlay2
DOCKER_TLS_CERTDIR: ""
# Name of the Gitlab project (use for name of docker image)
PROJECT_NAME: $CI_PROJECT_NAME
# ID of CI/CD Gitlab Job (use for tag of docker image)
PROJECT_TAG : $CI_PIPELINE_ID
script:
# docker login to Artifactory
- docker login -u $JFROG_USER -p $JFROG_PASS $JFROG_REPO
# docker build image with tag <image:tag>
- DOCKER_BUILDKIT=1 docker build --pull -t $PROJECT_NAME:$PROJECT_TAG /builds/$CI_PROJECT_NAMESPACE/$CI_PROJECT_NAME/docker-image/
- cd /usr/local/bin/
# docker tag image : <image:tag> <JFROG_REPO/image:tag>
- docker tag $PROJECT_NAME:$PROJECT_TAG $JFROG_REPO/$PROJECT_NAME:$PROJECT_TAG
# Docker push : <JFROG_REPO/image:tag>
- echo "LOG -> docker push $JFROG_REPO/$PROJECT_NAME:$PROJECT_TAG"
- docker push $JFROG_REPO/$PROJECT_NAME:$PROJECT_TAG
rules:
- exists:
- $CI_COMMIT_REF_NAME
install_helm:
stage: deploy
image:
name: alpine/helm:latest
entrypoint: [""]
variables:
# Kubernetes cluster configuration variables
K8_SERVER : [MY_SERVER_URL]
K8_CLUSTER : dev-cluster-bcu
K8_USER : dev-cluster-bcu
K8_TOKEN : [MY_TOKEN]
K8_NAMESPACE: kube-bs
K8_CONTEXT : kube-bs
# Name of the Gitlab project (use for name of docker image)
PROJECT_NAME: $CI_PROJECT_NAME
# ID of CI/CD Gitlab Job (use for tag of docker image)
PROJECT_TAG : $CI_PIPELINE_ID
script:
# Install docker
- apk add --no-cache docker
# Install kubectl
- curl -LO https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/amd64/kubectl
- chmod +x ./kubectl
- mv ./kubectl /usr/bin/kubectl
# Docker login to Container Registry (Artifactory)
- docker login -u $JFROG_USER -p $JFROG_PASS $JFROG_REPO
# Kubernetes cluster login (Rancher)
# Config cluster, credential, contexte
- kubectl config set-cluster $K8_CLUSTER --insecure-skip-tls-verify=true --server=$K8_SERVER
- kubectl config set-credentials $K8_USER --token=$K8_TOKEN
- kubectl config set-context $K8_CONTEXT --cluster=$K8_CLUSTER --user=$K8_USER --namespace=$K8_NAMESPACE
- kubectl config use-context $K8_CONTEXT
# Upgrade Helm Chart with image from CR
- cd /builds/$CI_PROJECT_NAMESPACE/$PROJECT_NAME/kubernet-chart/Helm
- echo "LOG -> helm upgrade --install $PROJECT_NAME $PROJECT_NAME --set container.image=$JFROG_REPO/$PROJECT_NAME,container.tag=$PROJECT_TAG"
- helm upgrade --install $PROJECT_NAME $PROJECT_NAME --set container.image=$JFROG_REPO/$PROJECT_NAME,container.tag=$PROJECT_TAG
rules:
- exists:
- $CI_COMMIT_REF_NAME
Thanks,
Dylan