diff --git a/Jenkinsfile b/Jenkinsfile index 75580ea..c9d0b56 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -28,18 +28,25 @@ 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: ''' + withCredentials([string(credentialsId: 'Gitea_Credentials', variable: 'GITEA_TOKEN')]) { + writeFile file: 'gitea-release.sh', text: ''' #!/bin/bash -# Define the APK file path -apkPath="build/outputs/apk/debug/app-debug.apk" +# Задаем путь к APK файлу +apkPath="app-debug.apk" -# Check if the APK exists +# Получаем артефакт из Jenkins +JENKINS_URL="https://jenkins.grigowashere.ru" +JOB_NAME="TestingAndroid" +BUILD_NUMBER="$BUILD_NUMBER" +ARTIFACT_PATH="app/build/outputs/apk/debug/app-debug.apk" +curl -O "$JENKINS_URL/job/$JOB_NAME/$BUILD_NUMBER/artifact/$ARTIFACT_PATH" + +# Проверяем, существует ли APK файл if [ ! -f "$apkPath" ]; then echo "APK file does not exist at $apkPath" exit 1 @@ -47,9 +54,10 @@ fi echo "APK file exists: $apkPath" +# Загружаем релиз на Gitea headers="Authorization: token $GITEA_TOKEN" -# Create the release on Gitea +# Создаем релиз в Gitea release=$(curl -X POST "https://git.grigowashere.ru/api/v1/repos/$GITEA_OWNER/$GITEA_REPO/releases" \ -H "$headers" \ -H "Content-Type: application/json" \ @@ -64,10 +72,10 @@ release=$(curl -X POST "https://git.grigowashere.ru/api/v1/repos/$GITEA_OWNER/$G releaseId=$(echo $release | jq -r .id) -# Form URL for uploading APK asset +# Формируем URL для загрузки APK uploadUrl="https://git.grigowashere.ru/api/v1/repos/$GITEA_OWNER/$GITEA_REPO/releases/$releaseId/assets?name=app-debug.apk" -# Upload APK file to Gitea +# Загружаем APK файл в Gitea curl -X POST "$uploadUrl" \ -H "$headers" \ -F "attachment=@$apkPath;type=application/vnd.android.package-archive" @@ -78,14 +86,14 @@ if [ $? -ne 0 ]; then fi ''' - sh ''' - chmod +x gitea-release.sh - ./gitea-release.sh - ''' - } - } + sh ''' + chmod +x gitea-release.sh + ./gitea-release.sh + ''' } } +} + } post { always {