-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJenkinsfile
52 lines (47 loc) · 2.26 KB
/
Jenkinsfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
pipeline {
agent any
stages {
stage('Build') {
steps {
script {
def commitSha = sh(returnStdout: true, script: 'git rev-parse HEAD').trim()
withCredentials([string(credentialsId: 'AzIsra', variable: 'AzIsra')]) {
sh """
curl -s -X POST -H "Authorization: token ${AzIsra}" \
-d '{"state": "pending", "target_url": "${env.BUILD_URL}", "description": "Build is in progress", "context": "Build"}' \
https://api.github.com/repos/AzIsra/JenkinsTest/statuses/${commitSha}
"""
}
// Example build command
sh 'ech "Hello World"'
}
}
post {
success {
script {
def commitSha = sh(returnStdout: true, script: 'git rev-parse HEAD').trim()
withCredentials([string(credentialsId: 'AzIsra', variable: 'AzIsra')]) {
sh """
curl -s -X POST -H "Authorization: token ${AzIsra}" \
-d '{"state": "success", "target_url": "${env.BUILD_URL}", "description": "Build completed successfully", "context": "Build"}' \
https://api.github.com/repos/AzIsra/JenkinsTest/statuses/${commitSha}
"""
}
}
}
failure {
script {
def commitSha = sh(returnStdout: true, script: 'git rev-parse HEAD').trim()
withCredentials([string(credentialsId: 'AzIsra', variable: 'AzIsra')]) {
sh """
curl -s -X POST -H "Authorization: token ${AzIsra}" \
-d '{"state": "failure", "target_url": "${env.BUILD_URL}", "description": "Build failed", "context": "Build"}' \
https://api.github.com/repos/AzIsra/JenkinsTest/statuses/${commitSha}
"""
}
}
}
}
}
}
}