From e4187998500dcb9dcd0d56afd5ef98de70f15abe Mon Sep 17 00:00:00 2001 From: yuobrezkov Date: Wed, 9 Apr 2025 14:56:41 +0300 Subject: [PATCH] =?UTF-8?q?=D0=BF=D1=80=D0=BE=D0=B2=D0=B5=D1=80=D0=BA?= =?UTF-8?q?=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Jenkinsfile | 40 +++++++++++++++++++++++----------------- 1 file changed, 23 insertions(+), 17 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 94bd441..ac2600a 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -26,22 +26,35 @@ pipeline { } environment { REGISTRY_NAME = 'registry.entcor/trust-module' - IMAGE_NAME = "trust-module-backend" + IMAGE_NAME = "test-ci-cd" GITEA_REPOSITORY_URL = "http://git.entcor/api/v1/repos/" } stages { stage ('Initialize variables') { steps { script { - // Читаем текущую версию из параметров - def (major, minor, patch) = params.PROJECT_VERSION.tokenize('.') - - // Увеличиваем патч (1.0.0 → 1.0.1) - patch = (patch as Integer) + 1 - env.IMAGE_TAG = "${major}.${minor}.${patch}" - - // Опционально: сохраняем новую версию в параметры через API (см. ниже) - echo "New version: ${env.IMAGE_TAG}" + withCredentials([usernamePassword(credentialsId: 'gitea_creds', usernameVariable: 'GITEA_USER', passwordVariable: 'GITEA_PASS')]) { + def lastVersion = sh(script: """ + curl -s -u "${GITEA_USER}:${GITEA_PASS}" \ + "${env.GITEA_REPOSITORY_URL}deployer3000/${env.IMAGE_NAME}/releases" | \ + jq -r '.[].tag_name' | sort -V | tail -n 1 + """, returnStdout: true).trim() + + if (!lastVersion) { + lastVersion = "0.0.0" + } + + def (major, minor, patch) = lastVersion.tokenize('.') + def newVersion = "${major}.${minor}.${patch.toInteger() + 1}" + env.IMAGE_TAG = newVersion + + sh """ + curl -X POST -u "${GITEA_USER}:${GITEA_PASS}" \ + -H "Content-Type: application/json" \ + -d '{"tag_name": "${newVersion}", "name": "Release ${newVersion}", "target_commitish": "${env.GIT_COMMIT}"}' \ + "${env.GITEA_REPOSITORY_URL}deployer3000/${env.IMAGE_NAME}/releases" + """ + } } } } @@ -93,13 +106,6 @@ pipeline { def context = "test-org/trust-module-backend/pipeline/pr-${env.CHANGE_TARGET}" def commitHash = sh(script: "git rev-parse HEAD~1", returnStdout: true).trim() notify(context, GITEA_USER, GITEA_PASS, env.GITEA_REPOSITORY_URL, "trust-module-backend", commitHash, "success") - - // Обновляем параметр PROJECT_VERSION через API (если нужно) - def newVersion = env.IMAGE_TAG - sh """ - curl -X POST -u ${GITEA_USER}:${GITEA_PASS} \ - "http://192.168.2.55:8080/job/${env.JOB_NAME}/buildWithParameters?PROJECT_VERSION=${newVersion}" - """ } } }