From 9e832ce9fa7b709007d933af5f0387fd5cc82d26 Mon Sep 17 00:00:00 2001 From: grigo Date: Sun, 3 May 2026 17:20:05 +0300 Subject: [PATCH] refs TG-3: added autoReleaswe --- Jenkinsfile | 87 ++++++++++++++++++++++++++++------------------------- 1 file changed, 46 insertions(+), 41 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index a36196b..75580ea 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -10,7 +10,6 @@ pipeline { TAIGA_URL = 'https://taiga.grigowashere.ru' GITEA_OWNER = 'Grigo' GITEA_REPO = 'TestingAndroidBuild' - } stages { @@ -29,56 +28,63 @@ pipeline { } } - stage('Create Gitea Release and Upload APK') { - steps { - unstash 'apk' + stage('Create Gitea Release and Upload APK') { + steps { + unstash 'apk' - withCredentials([string(credentialsId: 'Gitea_Credentials', variable: 'GITEA_TOKEN')]) { - writeFile file: 'gitea-release.sh', text: ''' - #!/bin/bash + withCredentials([string(credentialsId: 'Gitea_Credentials', variable: 'GITEA_TOKEN')]) { + writeFile file: 'gitea-release.sh', text: ''' +#!/bin/bash - apkPath="build/outputs/apk/debug/app-debug.apk" +# Define the APK file path +apkPath="build/outputs/apk/debug/app-debug.apk" - headers="Authorization: token $GITEA_TOKEN" +# Check if the APK exists +if [ ! -f "$apkPath" ]; then + echo "APK file does not exist at $apkPath" + exit 1 +fi - # Create the release on Gitea - release=$(curl -X POST "https://git.grigowashere.ru/api/v1/repos/$GITEA_OWNER/$GITEA_REPO/releases" \ - -H "$headers" \ - -H "Content-Type: application/json" \ - -d '{ - "tag_name": "v'$BUILD_NUMBER'", - "target_commitish": "main", - "name": "Release v'$BUILD_NUMBER'", - "body": "Jenkins Android build '$BUILD_NUMBER'", - "draft": false, - "prerelease": false - }') +echo "APK file exists: $apkPath" - releaseId=$(echo $release | jq -r .id) +headers="Authorization: token $GITEA_TOKEN" - # Form URL for uploading APK asset - uploadUrl="https://git.grigowashere.ru/api/v1/repos/$GITEA_OWNER/$GITEA_REPO/releases/$releaseId/assets?name=app-debug.apk" +# Create the release on Gitea +release=$(curl -X POST "https://git.grigowashere.ru/api/v1/repos/$GITEA_OWNER/$GITEA_REPO/releases" \ + -H "$headers" \ + -H "Content-Type: application/json" \ + -d '{ + "tag_name": "v'$BUILD_NUMBER'", + "target_commitish": "main", + "name": "Release v'$BUILD_NUMBER'", + "body": "Jenkins Android build '$BUILD_NUMBER'", + "draft": false, + "prerelease": false + }') - # Upload APK file to Gitea - curl -X POST "$uploadUrl" \ - -H "$headers" \ - -F "attachment=@$apkPath;type=application/vnd.android.package-archive" +releaseId=$(echo $release | jq -r .id) - if [ $? -ne 0 ]; then - echo "Gitea asset upload failed: $apkPath" - exit 1 - fi - ''' +# Form URL for uploading APK asset +uploadUrl="https://git.grigowashere.ru/api/v1/repos/$GITEA_OWNER/$GITEA_REPO/releases/$releaseId/assets?name=app-debug.apk" - sh ''' - chmod +x gitea-release.sh - ./gitea-release.sh - ''' - } - } - } +# Upload APK file to Gitea +curl -X POST "$uploadUrl" \ + -H "$headers" \ + -F "attachment=@$apkPath;type=application/vnd.android.package-archive" +if [ $? -ne 0 ]; then + echo "Gitea asset upload failed: $apkPath" + exit 1 +fi +''' + sh ''' + chmod +x gitea-release.sh + ./gitea-release.sh + ''' + } + } + } } post { @@ -104,7 +110,6 @@ pipeline { import json import os import urllib.request -import urllib.error taiga_url = os.environ["TAIGA_URL"] project_id = os.environ["TAIGA_PROJECT_ID"]