From fd9ea41c4b8ad3dced6bcaecd5f0e7c1222fcaf3 Mon Sep 17 00:00:00 2001 From: mh Date: Wed, 10 Jul 2024 00:56:30 -0700 Subject: [PATCH] Update 'Jenkinsfile' --- Jenkinsfile | 38 +++++++++++++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index acafac8..8826865 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -1,11 +1,19 @@ pipeline { agent any + + environment { + GITEA_CREDS = 'test' + GITEA_REPO_URL = 'https://github.com/mh-lornejad/jenkins-test3.git' + GITEA_TOKEN = 'your-gitea-token' + MAIN_BRANCH = 'token' + } + stages { stage('Clone the repo') { steps { echo "Clone the repo" sh "rm -fr jenkins-test3" - git branch: 'main', credentialsId: 'test', url: 'https://github.com/mh-lornejad/jenkins-test3.git' + git branch: "${env.MAIN_BRANCH}", credentialsId: "${env.GITEA_CREDS}", url: "${env.GITEA_REPO_URL}" } } stage('Code Analysis') { @@ -41,4 +49,32 @@ pipeline { } } } + + post { + always { + script { + def status = currentBuild.result == 'SUCCESS' ? 'success' : 'failure' + def state = status == 'success' ? 'success' : 'failure' + def description = "Jenkins build ${status}" + def commitSha = env.GIT_COMMIT + + httpRequest( + url: "${env.GITEA_REPO_URL}/statuses/${commitSha}", + httpMode: 'POST', + customHeaders: [ + [name: 'Content-Type', value: 'application/json'], + [name: 'Authorization', value: "token ${env.GITEA_TOKEN}"] + ], + requestBody: """ + { + "state": "${state}", + "target_url": "${env.BUILD_URL}", + "description": "${description}", + "context": "continuous-integration/jenkins" + } + """ + ) + } + } + } }