fix(jenkins) : fix check request from jenkins to gitea
All checks were successful
jenkins-ci Build successful
All checks were successful
jenkins-ci Build successful
This commit is contained in:
23
Jenkinsfile
vendored
23
Jenkinsfile
vendored
@@ -38,25 +38,24 @@ pipeline {
|
|||||||
def commitSha = sh(script: 'git rev-parse HEAD', returnStdout: true).trim()
|
def commitSha = sh(script: 'git rev-parse HEAD', returnStdout: true).trim()
|
||||||
|
|
||||||
// Convert from Jenkins to Gitea API
|
// Convert from Jenkins to Gitea API
|
||||||
def buildState = currentBuild.currentResult == 'SUCCESS' ? 'success' : 'failure'
|
def buildState = (currentBuild.currentResult == 'SUCCESS') ? 'success' : 'failure'
|
||||||
def buildDesc = currentBuild.currentResult == 'SUCCESS' ? 'Build successful' : 'Build failed'
|
def buildDesc = (currentBuild.currentResult == 'SUCCESS') ? 'Build successful' : 'Build failed'
|
||||||
|
|
||||||
// Send it to Gitea API with secret 'gitea-token'
|
// Send it to Gitea API with secret 'gitea-token'
|
||||||
withCredentials([string(credentialsId: 'gitea-token', variable: 'GITEA_TOKEN')]) {
|
withCredentials([string(credentialsId: 'gitea-token', variable: 'GITEA_TOKEN')]) {
|
||||||
sh "curl -f -X POST ${GITEA_API_URL}/repos/${GITEA_REPO_PATH}/statuses/${commitSha} " +
|
// Use \$TOKEN to avoid jenkins to print token in logs
|
||||||
"-H 'Authorization: token \$GITEA_TOKEN' " +
|
sh """
|
||||||
"-H 'Content-Type: application/json' " +
|
curl -f -X POST "${GITEA_API_URL}/repos/${GITEA_REPO_PATH}/statuses/${commitSha}" \
|
||||||
"-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"}'
|
||||||
|
"""
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
echo "Clean unused image..."
|
echo "Clean unused image..."
|
||||||
sh "docker image prune -f"
|
sh "docker image prune -f"
|
||||||
}
|
}
|
||||||
success {
|
success { echo "Success !" }
|
||||||
echo "Success !"
|
failure { echo "Failed." }
|
||||||
}
|
|
||||||
failure {
|
|
||||||
echo "Failed."
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user