проверка через build api
parent
63bc80fae5
commit
c7a8b4f66a
|
|
@ -0,0 +1,10 @@
|
|||
<component name="InspectionProjectProfileManager">
|
||||
<profile version="1.0">
|
||||
<option name="myName" value="Project Default" />
|
||||
<inspection_tool class="SpellCheckingInspection" enabled="true" level="INFORMATION" enabled_by_default="true">
|
||||
<option name="processCode" value="true" />
|
||||
<option name="processLiterals" value="true" />
|
||||
<option name="processComments" value="true" />
|
||||
</inspection_tool>
|
||||
</profile>
|
||||
</component>
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module version="4">
|
||||
<component name="Go" enabled="true" />
|
||||
</module>
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="" vcs="Git" />
|
||||
</component>
|
||||
</project>
|
||||
|
|
@ -0,0 +1,116 @@
|
|||
def notify(
|
||||
String context,
|
||||
String giteaUser,
|
||||
String giteaPass,
|
||||
String repositoryUrl,
|
||||
String repositoryName,
|
||||
String commitHash,
|
||||
String buildStatus
|
||||
) {
|
||||
def status = buildStatus == 'success' ? 'success' : 'failure'
|
||||
def description = buildStatus == 'success' ? 'Build succeeded' : 'Build failed'
|
||||
|
||||
sh """
|
||||
curl -X POST \
|
||||
-u "${giteaUser}:${giteaPass}" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{"context":"${context}","state": "${status}", "description": "${description}"}' \
|
||||
${repositoryUrl}deployer3000/${repositoryName}/statuses/${commitHash}
|
||||
"""
|
||||
}
|
||||
|
||||
pipeline {
|
||||
agent any
|
||||
parameters {
|
||||
string(name: 'PROJECT_VERSION', defaultValue: '1.0.0', description: 'SemVer version (e.g., 1.0.0)')
|
||||
}
|
||||
environment {
|
||||
REGISTRY_NAME = 'registry.entcor/trust-module'
|
||||
IMAGE_NAME = "trust-module-backend"
|
||||
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}"
|
||||
}
|
||||
}
|
||||
}
|
||||
stage ('Build docker image') {
|
||||
when {
|
||||
expression { env.CHANGE_BRANCH?.startsWith('rc') }
|
||||
}
|
||||
steps {
|
||||
script {
|
||||
def image = docker.build("${env.IMAGE_NAME}:${env.IMAGE_TAG}")
|
||||
sh "docker tag ${env.IMAGE_NAME}:${env.IMAGE_TAG} ${env.REGISTRY_NAME}/${env.IMAGE_NAME}:${env.IMAGE_TAG}"
|
||||
}
|
||||
}
|
||||
}
|
||||
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 {
|
||||
always {
|
||||
script {
|
||||
echo "Cleaning up workspace..."
|
||||
sh "rm -rf ${env.WORKSPACE}/rc/ || true"
|
||||
}
|
||||
}
|
||||
success {
|
||||
script {
|
||||
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')]) {
|
||||
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/trust-module-backend/pulls/${prId}/merge
|
||||
"""
|
||||
echo "PR ${prId} merged successfully into main!"
|
||||
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}"
|
||||
"""
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
failure {
|
||||
echo "Pipeline failed. Check the logs for details."
|
||||
}
|
||||
aborted {
|
||||
echo "Pipeline was aborted."
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//TODO: дженкинс entcor убрать
|
||||
Loading…
Reference in New Issue