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 수정/