diff --git a/Jenkinsfile b/Jenkinsfile index 18406c4..be11d15 100755 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -1,6 +1,11 @@ pipeline { agent any + environment { + GITEA_REPO_PATH = "server/reverse-proxy" + GITEA_API_URL = "https://gitea.lucasroyer.fr/api/v1" + } + stages { stage('Check git...') { steps { @@ -36,6 +41,24 @@ pipeline { post { always { + script { + // Get and store SHA + def commitSha = sh(script: 'git rev-parse HEAD', returnStdout: true).trim() + + // Convert from Jenkins to Gitea API + def buildState = currentBuild.currentResult == 'SUCCESS' ? 'success' : 'failure' + def buildDesc = currentBuild.currentResult == 'SUCCESS' ? 'Build successful' : 'Build failed' + + // Send it to Gitea API with secret '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"}' + """ + } + } echo "Clean unused image..." sh "docker image prune -f" }