Files
cicd_new_version/.gitlab-ci.yml
정훈 변 b89b1ce183 CI 수정
2024-08-01 15:55:43 +09:00

94 lines
2.9 KiB
YAML
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

stages:
- version_update
version_update:
image: harbor.exem-oss.org/test/test-runner:latest
stage: version_update
variables:
file1: "./old/old_version.json"
file2: "./new_version.json"
git_token: $TOKEN
git_user: $USER
git_url: $URL
before_script: |
git config --global user.email "sa_8001@ex-em.com"
git config --global user.name "변정훈"
git clone https://${git_user}:${git_token}@${git_url} ./old
script: |
jq_parse() {
jq -r '.[] | "\(.name):\(.version)"' "$1"
}
declare -A old_version
while IFS=: read -r name version; do
old_version["$name"]=$version
done < <(jq_parse "$file1")
declare -a different_names
declare -a different_versions
while IFS=: read -r name version; do
if [[ "${old_version["$name"]}" != "$version" ]]; then
different_names+=("$name")
different_versions+=("$version")
fi
done < <(jq_parse "$file2")
if [ ${#different_names[@]} -gt 0 ]; then
echo "" && echo ""
echo "아래 항목에 대해서 CI 작업을 시작합니다!" && echo ""
curl -i -X POST -H 'Content-Type: application/json' -d "{
\"username\": \"CI/CD\",
\"icon_url\": \"https://www.claranet.com/br/sites/all/assets/br/cicd-icon.svg\",
\"attachments\": [{
\"color\": \"#81F781\",
\"author_name\": \"CI 진행 목록\",
\"author_icon\": \"https://www.claranet.com/br/sites/all/assets/br/cicd-icon.svg\",
\"text\": \"$different_names\"
}]
}" https://chat.exem.io/hooks/d8eb7x771pdaiym8xfgju8mx8a
for index in "${!different_names[@]}"; do
name="${different_names[$index]}"
version="${different_versions[$index]}"
echo "$name:$version"
case $name in
exemone_java_agent)
curl -s -o /dev/null -X POST \
--fail \
-F "token=$JAVA_AGENT_TOKEN" \
-F "ref=main" \
-F "variables[TRIGGER_NAME]=exemone_java_agent" \
-F "variables[VER]=$version" \
https://lab.jhcloud.kr/api/v4/projects/53/trigger/pipeline
;;
exemone_kafka_agent)
curl -s -o /dev/null -X POST \
--fail \
-F "token=$KAFKA_AGENT_TOKEN" \
-F "ref=main" \
-F "variables[TRIGGER_NAME]=exemone_kafka_agent" \
-F "variables[VER]=$version" \
https://lab.jhcloud.kr/api/v4/projects/54/trigger/pipeline
;;
*)
echo "프로젝트 \"$name\"을(를) 찾을 수 없습니다!" && echo ""
;;
esac
done
echo "" && echo ""
cp $file2 $file1 && cd ./old
git add ./
git commit -m "버전 관리"
git push origin main
else
echo "" && echo "버전이 변한 애플리케이션이 없습니다." && echo ""
fi
except:
variables:
- $CI_COMMIT_MESSAGE =~ /CI 수정/