generated from Grigo/AndroidTemplate
Compare commits
2 Commits
cbcd3399b3
..
v6
| Author | SHA1 | Date | |
|---|---|---|---|
| 253a7d74ca | |||
| ab7c214966 |
Vendored
+6
-98
@@ -7,10 +7,8 @@ pipeline {
|
|||||||
ANDROID_SDK_ROOT = '/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}"
|
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'
|
|
||||||
GITEA_OWNER = 'Grigo'
|
GITEA_OWNER = 'Grigo'
|
||||||
GITEA_REPO = 'TestingAndroidBuild' // Замените на нужный репозиторий
|
GITEA_REPO = 'LoraMapTester' // Замените на нужный репозиторий
|
||||||
GITEA_URL = 'https://git.grigowashere.ru' // Базовый URL Gitea
|
GITEA_URL = 'https://git.grigowashere.ru' // Базовый URL Gitea
|
||||||
GITEA_API_URL = "${GITEA_URL}/api/v1"
|
GITEA_API_URL = "${GITEA_URL}/api/v1"
|
||||||
GITEA_TOKEN_CREDENTIALS_ID = 'Gitea_Credentials' // ID ваших креденшлов для Gitea в Jenkins
|
GITEA_TOKEN_CREDENTIALS_ID = 'Gitea_Credentials' // ID ваших креденшлов для Gitea в Jenkins
|
||||||
@@ -40,7 +38,11 @@ pipeline {
|
|||||||
writeFile file: 'gitea-release.sh', text: '''
|
writeFile file: 'gitea-release.sh', text: '''
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
apkPath="build/outputs/apk/debug/app-debug.apk"
|
apkPath=$(find . -path '*/build/outputs/apk/debug/*.apk' -type f | head -1)
|
||||||
|
if [ -z "$apkPath" ]; then
|
||||||
|
echo "APK not found under */build/outputs/apk/debug/"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
headers="Authorization: token $GITEA_TOKEN"
|
headers="Authorization: token $GITEA_TOKEN"
|
||||||
|
|
||||||
# Создаем релиз на Gitea
|
# Создаем релиз на Gitea
|
||||||
@@ -80,98 +82,4 @@ fi
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
post {
|
|
||||||
always {
|
|
||||||
script {
|
|
||||||
def result = currentBuild.currentResult ?: 'UNKNOWN'
|
|
||||||
|
|
||||||
withCredentials([string(credentialsId: 'TAIGA_TOKEN', variable: 'TAIGA_TOKEN')]) {
|
|
||||||
sh(returnStatus: true, script: """
|
|
||||||
set +e
|
|
||||||
|
|
||||||
REF=\$(git log -1 --pretty=%B | grep -oE 'TG-[0-9]+' | head -1 | cut -d- -f2 || true)
|
|
||||||
|
|
||||||
if [ -z "\$REF" ]; then
|
|
||||||
echo "No TG-* reference found"
|
|
||||||
exit 0
|
|
||||||
fi
|
|
||||||
|
|
||||||
export REF
|
|
||||||
export BUILD_RESULT="${result}"
|
|
||||||
|
|
||||||
python3 - <<'PY'
|
|
||||||
import json
|
|
||||||
import os
|
|
||||||
import urllib.request
|
|
||||||
|
|
||||||
taiga_url = os.environ["TAIGA_URL"]
|
|
||||||
project_id = os.environ["TAIGA_PROJECT_ID"]
|
|
||||||
token = os.environ["TAIGA_TOKEN"]
|
|
||||||
ref = os.environ["REF"]
|
|
||||||
|
|
||||||
headers = {
|
|
||||||
"Authorization": f"Bearer {token}",
|
|
||||||
"Content-Type": "application/json",
|
|
||||||
}
|
|
||||||
|
|
||||||
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 Exception:
|
|
||||||
return None
|
|
||||||
|
|
||||||
targets = [
|
|
||||||
("userstories", "User Story"),
|
|
||||||
("issues", "Issue"),
|
|
||||||
("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")
|
|
||||||
raise SystemExit(0)
|
|
||||||
|
|
||||||
endpoint, label, data = found
|
|
||||||
|
|
||||||
comment = (
|
|
||||||
f"Jenkins Android 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']}"
|
|
||||||
req = urllib.request.Request(
|
|
||||||
url,
|
|
||||||
data=payload,
|
|
||||||
headers=headers,
|
|
||||||
method="PATCH",
|
|
||||||
)
|
|
||||||
|
|
||||||
try:
|
|
||||||
with urllib.request.urlopen(req) as r:
|
|
||||||
print(f"Commented Taiga TG-{ref} ({label}), HTTP {r.status}")
|
|
||||||
except Exception as e:
|
|
||||||
print(f"Taiga comment warning: {e}")
|
|
||||||
raise SystemExit(0)
|
|
||||||
PY
|
|
||||||
""".stripIndent())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user