14
Jenkinsfile
vendored
14
Jenkinsfile
vendored
@@ -42,20 +42,20 @@ pipeline {
|
||||
post {
|
||||
always {
|
||||
script {
|
||||
// Fetch the current commit SHA
|
||||
// 1. Get current commit SHA
|
||||
def commitSha = sh(script: 'git rev-parse HEAD', returnStdout: true).trim()
|
||||
|
||||
// Define build status and description based on current result
|
||||
// 2. Determine build status for Gitea
|
||||
def buildState = currentBuild.currentResult == 'SUCCESS' ? 'success' : 'failure'
|
||||
def buildDesc = currentBuild.currentResult == 'SUCCESS' ? 'Build successful' : 'Build failed'
|
||||
|
||||
// Notify Gitea using the API (requires credential in Jenkins)
|
||||
withCredentials([[$class: 'StringBinding', credentialsId: 'jenkins', variable: 'GITEA_TOKEN']]) {
|
||||
// 3. Send status to Gitea API using our new 'gitea-token'
|
||||
withCredentials([string(credentialsId: 'gitea-token', variable: 'GITEA_TOKEN')]) {
|
||||
sh """
|
||||
curl -f -X POST "${GITEA_API_URL}/repos/${GITEA_REPO_PATH}/statuses/${commitSha}" \
|
||||
-H "Authorization: token ${GITEA_TOKEN}" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{"state": "${buildState}", "target_url": "${env.BUILD_URL}", "description": "${buildDesc}", "context": "jenkins-ci"}'
|
||||
-H "Authorization: token ${GITEA_TOKEN}" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{"state": "${buildState}", "target_url": "${env.BUILD_URL}", "description": "${buildDesc}", "context": "jenkins-ci"}'
|
||||
"""
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user