I have written a GitLab CICD pipeline. So that when the two file in repo GKE
got changed then it should trigger the GitLab CICD pipeline in the other repo branch feature/ABC-123-Server-Update-Component-And-Unit-Test
, named repo Exp
, while also passing that the file is changed in dev
branch or prod
branch.
Here is the .gitlab-ci.yml
file for the repo "GKE" repo:
default:
tags:
- docker
stages:
- server-update
server-update:
stage: server-update
script:
- |
if [[ $(git diff --name-only $CI_COMMIT_BEFORE_SHA $CI_COMMIT_SHA) == *"lib/abc/argo-app.yml"* && $(git diff --name-only $CI_COMMIT_BEFORE_SHA $CI_COMMIT_SHA) == *"env/dev/mlops/tool/patch-argo-app.yml"* ]]; then
echo "Server Updated in Dev Branch"
curl -X POST \
-F token=$CI_JOB_TOKEN \
-F "ref=feature/ABC-123-Server-Update-Component-And-Unit-Test" \
-F "variables[TRIGGER_BRANCH]=feature/ABC-123-Server-Update-Component-And-Unit-Test" \
-F "variables[TRIGGER_PROJECT]=pro/Exp" \
-F "variables[ENVIRONMENT]=dev" \
https://git.swf.company.com/api/v4/projects/pro/Exp/trigger/pipeline
elif [[ $(git diff --name-only $CI_COMMIT_BEFORE_SHA $CI_COMMIT_SHA) == *"lib/abc/argo-app.yml"* && $(git diff --name-only $CI_COMMIT_BEFORE_SHA $CI_COMMIT_SHA) == *"env/prod/mlops/tool/patch-argo-app.yml"* ]]; then
echo "WandB Server Updated in Prod Branch"
curl -X POST \
-F token=$CI_JOB_TOKEN \
-F "ref=feature/ABC-123-Server-Update-Component-And-Unit-Test" \
-F "variables[TRIGGER_BRANCH]=feature/ABC-123-Server-Update-Component-And-Unit-Test" \
-F "variables[TRIGGER_PROJECT]=pro/Exp" \
-F "variables[ENVIRONMENT]=prod" \
https://git.swf.company.com/api/v4/projects/pro/Exp/trigger/pipeline
else
echo "No Change in Server"
fi
For testing purpose, I changed the files argo-app.yml
and patch-argo-app.yml
, the pipeline is triggered but at the I got the message that
/scripts-34677-15023504/step_script: line 149: git: command not found
/scripts-34677-15023504/step_script: line 158: git: command not found
No Change in Server
Although I changed the files but it didn't detected the change. What is wrong in my CICD pipeline ?
Thanks !!!
I found out that the issue was in my logic. I simplified it and divided it into two jobs:
# Stage to Trigger the pipeline when the Server in Dev is updated.
dev-server-update:
stage: dev-server-update
only:
changes:
- "lib/abc/argo-app.yml"
- "env/dev/mlops/tool/patch-argo-app.yml"
variables:
ENV: "dev"
trigger:
project: project/Experiment
branch: feature/ABC-123-Server-Update-Component-And-Unit-Test
forward:
pipeline_variables: true
# Stage to Trigger the pipeline when the Server in Prod is updated.
prod-server-update:
stage: prod-server-update
only:
changes:
- "lib/abc/argo-app.yml"
- "env/prod/mlops/tool/patch-argo-app.yml"
variables:
ENV: "prod"
trigger:
project: project/Experiment
branch: feature/ABC-123-Server-Update-Component-And-Unit-Test
forward:
pipeline_variables: true