From b1c882741e432e33cc914c28f9506b631aac6ff2 Mon Sep 17 00:00:00 2001 From: grigo Date: Sat, 2 May 2026 18:38:17 +0300 Subject: [PATCH] refs TG-2: add test Jenkins2 --- Jenkinsfile | 50 ++++++++++++++++++++++++++------------------------ 1 file changed, 26 insertions(+), 24 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index c925985..976b377 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -23,44 +23,46 @@ environment { } } } - post { - always { +post { + always { + script { + def result = currentBuild.currentResult ?: 'UNKNOWN' + withCredentials([string(credentialsId: 'TAIGA_TOKEN', variable: 'TAIGA_TOKEN')]) { - sh ''' + sh """ set -e - REF=$(git log -1 --pretty=%B | grep -oE 'TG-[0-9]+' | head -1 | cut -d- -f2) + REF=\$(git log -1 --pretty=%B | grep -oE 'TG-[0-9]+' | head -1 | cut -d- -f2 || true) - if [ -z "$REF" ]; then + if [ -z "\$REF" ]; then echo "No TG-* reference found" exit 0 fi - STATUS="${currentBuild.currentResult}" - COMMENT="Jenkins build #${BUILD_NUMBER}: ${STATUS}\\n${BUILD_URL}" + ISSUE_JSON=\$(curl -s \\ + -H "Authorization: Bearer \$TAIGA_TOKEN" \\ + "https://taiga.grigowashere.ru/api/v1/issues/by_ref?project=2&ref=\$REF") - ISSUE_JSON=$(curl -s \ - -H "Authorization: Bearer ${TAIGA_TOKEN}" \ - "https://taiga.grigowashere.ru/api/v1/issues/by_ref?project=2&ref=${REF}") + ISSUE_ID=\$(echo "\$ISSUE_JSON" | python3 -c 'import sys,json; print(json.load(sys.stdin)["id"])') + VERSION=\$(echo "\$ISSUE_JSON" | python3 -c 'import sys,json; print(json.load(sys.stdin)["version"])') - ISSUE_ID=$(echo "$ISSUE_JSON" | python3 -c 'import sys,json; print(json.load(sys.stdin)["id"])') - VERSION=$(echo "$ISSUE_JSON" | python3 -c 'import sys,json; print(json.load(sys.stdin)["version"])') + export COMMENT="Jenkins build #${BUILD_NUMBER}: ${result} +${BUILD_URL}" + export VERSION="\$VERSION" - python3 - < /tmp/taiga-comment.json - import json - comment = """${COMMENT}""" - print(json.dumps({"comment": comment, "version": int("${VERSION}")})) - PY + python3 -c 'import json, os; print(json.dumps({"comment": os.environ["COMMENT"], "version": int(os.environ["VERSION"])}))' \\ + > /tmp/taiga-comment.json - curl -s -X POST \ - -H "Authorization: Bearer ${TAIGA_TOKEN}" \ - -H "Content-Type: application/json" \ - --data @/tmp/taiga-comment.json \ - "https://taiga.grigowashere.ru/api/v1/issues/${ISSUE_ID}/comments" + curl -s -X POST \\ + -H "Authorization: Bearer \$TAIGA_TOKEN" \\ + -H "Content-Type: application/json" \\ + --data @/tmp/taiga-comment.json \\ + "https://taiga.grigowashere.ru/api/v1/issues/\$ISSUE_ID/comments" - echo "Commented Taiga TG-${REF}" - ''' + echo "Commented Taiga TG-\$REF" + """.stripIndent() } } } +} } \ No newline at end of file