Проверка 9
parent
e9f44ff534
commit
cbc99deb36
|
|
@ -12,7 +12,7 @@ def notify(
|
||||||
|
|
||||||
sh """
|
sh """
|
||||||
curl -X POST \
|
curl -X POST \
|
||||||
-u "${giteaUser}:${giteaPass}" \
|
-u "\${giteaUser}:\${giteaPass}" \
|
||||||
-H "Content-Type: application/json" \
|
-H "Content-Type: application/json" \
|
||||||
-d '{"context":"${context}","state": "${status}", "description": "${description}"}' \
|
-d '{"context":"${context}","state": "${status}", "description": "${description}"}' \
|
||||||
${repositoryUrl}deployer3000/${repositoryName}/statuses/${commitHash}
|
${repositoryUrl}deployer3000/${repositoryName}/statuses/${commitHash}
|
||||||
|
|
@ -21,6 +21,13 @@ def notify(
|
||||||
|
|
||||||
pipeline {
|
pipeline {
|
||||||
agent any
|
agent any
|
||||||
|
parameters {
|
||||||
|
string(
|
||||||
|
name: 'VERSION',
|
||||||
|
description: 'Версия в формате X.Y.Z (например, 1.0.0). Оставьте пустым для автоматического определения',
|
||||||
|
trim: true
|
||||||
|
)
|
||||||
|
}
|
||||||
environment {
|
environment {
|
||||||
REGISTRY_NAME = 'registry.entcor/trust-module'
|
REGISTRY_NAME = 'registry.entcor/trust-module'
|
||||||
IMAGE_NAME = "test-ci-cd"
|
IMAGE_NAME = "test-ci-cd"
|
||||||
|
|
@ -30,21 +37,34 @@ pipeline {
|
||||||
stage ('Initialize variables') {
|
stage ('Initialize variables') {
|
||||||
steps {
|
steps {
|
||||||
script {
|
script {
|
||||||
withCredentials([usernamePassword(credentialsId: 'gitea_creds', usernameVariable: 'GITEA_USER', passwordVariable: 'GITEA_PASS')]) {
|
// Если версия указана в параметрах - используем её
|
||||||
def lastVersion = sh(script: """
|
if (params.VERSION) {
|
||||||
curl -s -u "${GITEA_USER}:${GITEA_PASS}" \
|
env.IMAGE_TAG = params.VERSION
|
||||||
"${env.GITEA_REPOSITORY_URL}deployer3000/${env.IMAGE_NAME}/releases" | \
|
env.NEW_VERSION = params.VERSION
|
||||||
sed -n 's/.*"tag_name": *"\\([^"]*\\).*/\\1/p' | sort -V | tail -n1
|
echo "Using manual version: ${params.VERSION}"
|
||||||
""", returnStdout: true).trim()
|
}
|
||||||
|
// Иначе пытаемся получить последнюю версию из Gitea
|
||||||
|
else {
|
||||||
|
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" | \
|
||||||
|
sed -n 's/.*"tag_name": *"\\([^"]*\\).*/\\1/p' | sort -V | tail -n1
|
||||||
|
""", returnStdout: true).trim()
|
||||||
|
|
||||||
if (!lastVersion) {
|
if (!lastVersion) {
|
||||||
lastVersion = "0.0.0"
|
lastVersion = "0.0.0"
|
||||||
|
echo "No versions found in Gitea, using default: ${lastVersion}"
|
||||||
|
} else {
|
||||||
|
echo "Found last version in Gitea: ${lastVersion}"
|
||||||
|
}
|
||||||
|
|
||||||
|
// Инкрементим версию
|
||||||
|
def (major, minor, patch) = lastVersion.tokenize('.')
|
||||||
|
def newVersion = "${major}.${minor}.${patch.toInteger() + 1}"
|
||||||
|
env.IMAGE_TAG = newVersion
|
||||||
|
env.NEW_VERSION = newVersion
|
||||||
}
|
}
|
||||||
sh "echo ${lastVersion}"
|
|
||||||
def (major, minor, patch) = lastVersion.tokenize('.')
|
|
||||||
def newVersion = "${major}.${minor}.${patch.toInteger() + 1}"
|
|
||||||
env.IMAGE_TAG = newVersion
|
|
||||||
env.NEW_VERSION = newVersion
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -60,61 +80,39 @@ pipeline {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// stage ('Push docker image to registry') {
|
|
||||||
// when {
|
|
||||||
// expression { env.CHANGE_BRANCH?.startsWith('rc') }
|
|
||||||
// }
|
|
||||||
// steps {
|
|
||||||
// script {
|
|
||||||
// docker.withRegistry('https://registry.entcor/harbor/', 'harbor-credentials-id') {
|
|
||||||
// docker.image("${env.REGISTRY_NAME}/${env.IMAGE_NAME}:${env.IMAGE_TAG}").push()
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
post {
|
post {
|
||||||
always {
|
|
||||||
script {
|
|
||||||
echo "Cleaning up workspace..."
|
|
||||||
sh "rm -rf ${env.WORKSPACE}/rc/ || true"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
success {
|
success {
|
||||||
script {
|
script {
|
||||||
if (env.CHANGE_BRANCH?.startsWith('rc')) {
|
if (env.CHANGE_BRANCH?.startsWith('rc')) {
|
||||||
echo "Attempting to merge PR ${env.CHANGE_ID} into master..."
|
|
||||||
withCredentials([usernamePassword(credentialsId: 'gitea_creds', usernameVariable: 'GITEA_USER', passwordVariable: 'GITEA_PASS')]) {
|
withCredentials([usernamePassword(credentialsId: 'gitea_creds', usernameVariable: 'GITEA_USER', passwordVariable: 'GITEA_PASS')]) {
|
||||||
|
// Создаем релиз только если версия НЕ была указана вручную
|
||||||
|
if (!params.VERSION) {
|
||||||
|
sh """
|
||||||
|
curl -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": "${env.GIT_COMMIT}"}' \
|
||||||
|
"${env.GITEA_REPOSITORY_URL}deployer3000/${env.IMAGE_NAME}/releases"
|
||||||
|
"""
|
||||||
|
echo "New release ${env.NEW_VERSION} created in Gitea"
|
||||||
|
}
|
||||||
|
|
||||||
|
// Остальной код (мердж PR, нотификации)
|
||||||
def prId = env.CHANGE_ID
|
def prId = env.CHANGE_ID
|
||||||
sh """
|
sh """
|
||||||
curl -X POST \
|
curl -X POST \
|
||||||
-u "${GITEA_USER}:${GITEA_PASS}" \
|
-u "\${GITEA_USER}:\${GITEA_PASS}" \
|
||||||
-H "Content-Type: application/json" \
|
-H "Content-Type: application/json" \
|
||||||
-d '{"do":"merge"}' \
|
-d '{"do":"merge"}' \
|
||||||
http://git.entcor/api/v1/repos/deployer3000/${env.IMAGE_NAME}/pulls/${prId}/merge
|
"http://git.entcor/api/v1/repos/deployer3000/${env.IMAGE_NAME}/pulls/${prId}/merge"
|
||||||
"""
|
"""
|
||||||
echo "PR ${prId} merged successfully into main!"
|
|
||||||
sh """
|
def context = "test-org/${env.IMAGE_NAME}/pipeline/pr-${env.CHANGE_TARGET}"
|
||||||
curl -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": "${env.GIT_COMMIT}"}' \
|
|
||||||
"${env.GITEA_REPOSITORY_URL}deployer3000/${env.IMAGE_NAME}/releases"
|
|
||||||
"""
|
|
||||||
echo "New release succeeded!"
|
|
||||||
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, env.IMAGE_NAME, commitHash, "success")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
failure {
|
|
||||||
echo "Pipeline failed. Check the logs for details."
|
|
||||||
}
|
|
||||||
aborted {
|
|
||||||
echo "Pipeline was aborted."
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO: дженкинс entcor убрать
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue