From 85c7422735b58ee6908cfdfe654f98e1fee8f056 Mon Sep 17 00:00:00 2001 From: yuobrezkov Date: Thu, 10 Apr 2025 11:37:02 +0300 Subject: [PATCH 1/2] auto versioning added --- Jenkinsfile | 37 ++++++++++++++++++++++++++++++++++--- 1 file changed, 34 insertions(+), 3 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 796dc26..f1b31fa 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -13,7 +13,23 @@ pipeline { } steps { script { - env.IMAGE_TAG = sh(script: "git describe --tags --abbrev=0", returnStdout: true).trim() + def hasTags = sh(script: "git tag -l | wc -l", returnStdout: true).trim().toInteger() > 0 + echo "${hasTags}" + + def lastVersion = "0.0.0" + + if (hasTags) { + lastVersion = sh(script: "git describe --tags --abbrev=0", returnStdout: true).trim() + } + + echo "Last version: ${lastVersion}" + + def (major, minor, patch) = lastVersion.tokenize('.') + def newVersion = "${major}.${minor}.${patch.toInteger() + 1}" + echo "New version: ${newVersion}" + + env.IMAGE_TAG = newVersion + env.NEW_VERSION = newVersion } } } @@ -58,14 +74,29 @@ pipeline { echo "Attempting to merge PR ${env.CHANGE_ID} into master..." withCredentials([usernamePassword(credentialsId: 'gitea_creds', usernameVariable: 'GITEA_USER', passwordVariable: 'GITEA_PASS')]) { def prId = env.CHANGE_ID + sh """ curl -X POST \ -u "${GITEA_USER}:${GITEA_PASS}" \ -H "Content-Type: application/json" \ -d '{"do":"merge"}' \ - http://git.entcor/api/v1/repos/deployer3000/prometheus-exporter/pulls/${prId}/merge + http://git.entcor/api/v1/repos/deployer3000/${env.IMAGE_NAME}/pulls/${prId}/merge """ - echo "PR ${prId} merged successfully into master!" + def commitHash = sh(script: "git rev-parse HEAD~1", returnStdout: true).trim() // необходим для корректного отображения статусов + echo "PR ${prId} merged successfully into main!" + sleep(time: 15, unit: 'SECONDS') + sh "git checkout main && git pull origin main" + + sh """ + curl -v -X POST -u "${GITEA_USER}:${GITEA_PASS}" \ + -H "Content-Type: application/json" \ + -d '{"tag_name": "${env.NEW_VERSION}", "name": "Release ${env.NEW_VERSION}", "target_commitish": "main"}' \ + "${env.GITEA_REPOSITORY_URL}deployer3000/${env.IMAGE_NAME}/releases" + """ + echo "New release succeeded!" + + def context = "test-org/${env.IMAGE_NAME}/pipeline/pr-${env.CHANGE_TARGET}" + notify(context, GITEA_USER, GITEA_PASS, env.GITEA_REPOSITORY_URL, env.IMAGE_NAME, commitHash, "success") } } } From ca09d2c44c5505fa5659e61536bf4a7ddcf704d6 Mon Sep 17 00:00:00 2001 From: yuobrezkov Date: Thu, 10 Apr 2025 11:40:21 +0300 Subject: [PATCH 2/2] changed main to master --- Jenkinsfile | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index f1b31fa..47c15d6 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -83,14 +83,14 @@ pipeline { http://git.entcor/api/v1/repos/deployer3000/${env.IMAGE_NAME}/pulls/${prId}/merge """ def commitHash = sh(script: "git rev-parse HEAD~1", returnStdout: true).trim() // необходим для корректного отображения статусов - echo "PR ${prId} merged successfully into main!" + echo "PR ${prId} merged successfully into master!" sleep(time: 15, unit: 'SECONDS') - sh "git checkout main && git pull origin main" + sh "git checkout master && git pull origin master" sh """ curl -v -X POST -u "${GITEA_USER}:${GITEA_PASS}" \ -H "Content-Type: application/json" \ - -d '{"tag_name": "${env.NEW_VERSION}", "name": "Release ${env.NEW_VERSION}", "target_commitish": "main"}' \ + -d '{"tag_name": "${env.NEW_VERSION}", "name": "Release ${env.NEW_VERSION}", "target_commitish": "master"}' \ "${env.GITEA_REPOSITORY_URL}deployer3000/${env.IMAGE_NAME}/releases" """ echo "New release succeeded!"