-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
62 lines (58 loc) · 2.27 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
53
54
55
56
57
58
59
60
61
62
pipeline {
agent { label 'docker-slave' }
environment {
RECIPIENTS = '[email protected]' // Add your email address here
}
stages {
stage('Test') {
steps {
echo "Running tests for branch ${env.BRANCH_NAME}..."
// Simulate a failure for testing purposes
// sh 'exit 1' // Uncomment this to simulate failure
}
}
stage('Build') {
steps {
echo "Building the project for branch ${env.BRANCH_NAME}..."
}
}
}
post {
success {
script {
// Get the latest commit hash
def commitHash = sh(script: "git rev-parse --short HEAD", returnStdout: true).trim()
mail to: "${env.RECIPIENTS}",
subject: "Build Success: ${env.JOB_NAME} ${env.BUILD_NUMBER}",
body: """The build for branch ${env.BRANCH_NAME} was successful!
Commit ID: ${commitHash}
Build URL: ${env.BUILD_URL}"""
}
}
failure {
script {
// Get the latest commit hash
def commitHash = sh(script: "git rev-parse --short HEAD", returnStdout: true).trim()
mail to: "${env.RECIPIENTS}",
subject: "Build Failure: ${env.JOB_NAME} ${env.BUILD_NUMBER}",
body: """The build for branch ${env.BRANCH_NAME} failed.
Commit ID: ${commitHash}
Build URL: ${env.BUILD_URL}"""
}
}
unstable {
script {
// Get the latest commit hash
def commitHash = sh(script: "git rev-parse --short HEAD", returnStdout: true).trim()
mail to: "${env.RECIPIENTS}",
subject: "Build Unstable: ${env.JOB_NAME} ${env.BUILD_NUMBER}",
body: """The build for branch ${env.BRANCH_NAME} is unstable.
Commit ID: ${commitHash}
Build URL: ${env.BUILD_URL}"""
}
}
always {
echo 'This will always run, regardless of the build result.'
}
}
}