проверка

pull/1/head
yuobrezkov 2025-04-09 14:56:41 +03:00
parent c7a8b4f66a
commit e418799850
1 changed files with 23 additions and 17 deletions

36
Jenkinsfile vendored
View File

@ -26,22 +26,35 @@ pipeline {
} }
environment { environment {
REGISTRY_NAME = 'registry.entcor/trust-module' 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/" GITEA_REPOSITORY_URL = "http://git.entcor/api/v1/repos/"
} }
stages { stages {
stage ('Initialize variables') { stage ('Initialize variables') {
steps { steps {
script { script {
// Читаем текущую версию из параметров withCredentials([usernamePassword(credentialsId: 'gitea_creds', usernameVariable: 'GITEA_USER', passwordVariable: 'GITEA_PASS')]) {
def (major, minor, patch) = params.PROJECT_VERSION.tokenize('.') 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()
// Увеличиваем патч (1.0.0 → 1.0.1) if (!lastVersion) {
patch = (patch as Integer) + 1 lastVersion = "0.0.0"
env.IMAGE_TAG = "${major}.${minor}.${patch}" }
// Опционально: сохраняем новую версию в параметры через API (см. ниже) def (major, minor, patch) = lastVersion.tokenize('.')
echo "New version: ${env.IMAGE_TAG}" 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 context = "test-org/trust-module-backend/pipeline/pr-${env.CHANGE_TARGET}"
def commitHash = sh(script: "git rev-parse HEAD~1", returnStdout: true).trim() 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") 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}"
"""
} }
} }
} }