refs TG-2: test Jenkins comment
This commit is contained in:
Vendored
+69
-18
@@ -1,15 +1,17 @@
|
||||
pipeline {
|
||||
agent any
|
||||
|
||||
stages {
|
||||
stage('Build Android APK') {
|
||||
environment {
|
||||
JAVA_HOME = '/usr/lib/jvm/java-21-openjdk-amd64'
|
||||
ANDROID_HOME = '/opt/android-sdk'
|
||||
ANDROID_SDK_ROOT = '/opt/android-sdk'
|
||||
PATH = "/usr/lib/jvm/java-21-openjdk-amd64/bin:/opt/android-sdk/cmdline-tools/latest/bin:/opt/android-sdk/platform-tools:${env.PATH}"
|
||||
TAIGA_PROJECT_ID = '2'
|
||||
TAIGA_URL = 'https://taiga.grigowashere.ru'
|
||||
}
|
||||
|
||||
stages {
|
||||
stage('Build Android APK') {
|
||||
steps {
|
||||
cleanWs()
|
||||
checkout scm
|
||||
@@ -23,6 +25,7 @@ environment {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
post {
|
||||
always {
|
||||
script {
|
||||
@@ -39,27 +42,75 @@ post {
|
||||
exit 0
|
||||
fi
|
||||
|
||||
ISSUE_JSON=\$(curl -s \\
|
||||
-H "Authorization: Bearer \$TAIGA_TOKEN" \\
|
||||
"https://taiga.grigowashere.ru/api/v1/issues/by_ref?project=2&ref=\$REF")
|
||||
export REF
|
||||
export BUILD_RESULT="${result}"
|
||||
|
||||
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"])')
|
||||
python3 - <<'PY'
|
||||
import json
|
||||
import os
|
||||
import urllib.request
|
||||
import urllib.error
|
||||
|
||||
export COMMENT="Jenkins build #${BUILD_NUMBER}: ${result}
|
||||
${BUILD_URL}"
|
||||
export VERSION="\$VERSION"
|
||||
taiga_url = os.environ["TAIGA_URL"]
|
||||
project_id = os.environ["TAIGA_PROJECT_ID"]
|
||||
token = os.environ["TAIGA_TOKEN"]
|
||||
ref = os.environ["REF"]
|
||||
|
||||
python3 -c 'import json, os; print(json.dumps({"comment": os.environ["COMMENT"], "version": int(os.environ["VERSION"])}))' \\
|
||||
> /tmp/taiga-comment.json
|
||||
headers = {
|
||||
"Authorization": f"Bearer {token}",
|
||||
"Content-Type": "application/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"
|
||||
def get_json(path):
|
||||
url = f"{taiga_url}{path}"
|
||||
req = urllib.request.Request(url, headers=headers)
|
||||
try:
|
||||
with urllib.request.urlopen(req) as r:
|
||||
return json.loads(r.read().decode("utf-8"))
|
||||
except urllib.error.HTTPError:
|
||||
return None
|
||||
|
||||
echo "Commented Taiga TG-\$REF"
|
||||
targets = [
|
||||
("issues", "Issue"),
|
||||
("userstories", "User Story"),
|
||||
("tasks", "Task"),
|
||||
]
|
||||
|
||||
found = None
|
||||
|
||||
for endpoint, label in targets:
|
||||
data = get_json(f"/api/v1/{endpoint}/by_ref?project={project_id}&ref={ref}")
|
||||
if data and "id" in data:
|
||||
found = (endpoint, label, data)
|
||||
break
|
||||
|
||||
if not found:
|
||||
print(f"Taiga TG-{ref} not found as issue/userstory/task")
|
||||
raise SystemExit(0)
|
||||
|
||||
endpoint, label, data = found
|
||||
|
||||
comment = (
|
||||
f"Jenkins build #{os.environ['BUILD_NUMBER']}: {os.environ['BUILD_RESULT']}\\n"
|
||||
f"{os.environ['BUILD_URL']}"
|
||||
)
|
||||
|
||||
payload = json.dumps({
|
||||
"comment": comment,
|
||||
"version": data["version"],
|
||||
}).encode("utf-8")
|
||||
|
||||
url = f"{taiga_url}/api/v1/{endpoint}/{data['id']}/comments"
|
||||
req = urllib.request.Request(
|
||||
url,
|
||||
data=payload,
|
||||
headers=headers,
|
||||
method="POST",
|
||||
)
|
||||
|
||||
with urllib.request.urlopen(req) as r:
|
||||
print(f"Commented Taiga TG-{ref} ({label}), HTTP {r.status}")
|
||||
PY
|
||||
""".stripIndent()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user