-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathJenkinsfile
68 lines (63 loc) · 1.79 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
63
64
65
66
67
68
node {
try {
stage('Checkout') {
checkout scm
notifyBuild('STARTED')
}
stage('Environment') {
sh 'git --version'
echo "Branch: ${env.BRANCH_NAME}"
sh 'docker -v'
sh 'printenv'
}
stage('Build Docker test') {
echo "Build Docker Test"
}
stage('Docker test') {
echo "Dokcer test"
}
stage('Clean Docker test'){
echo "Clean Docker test"
}
stage('Push Image') {
if(env.BRANCH_NAME == 'master') {
sh('deploy/image.sh')
}
}
stage('Deploy') {
sh('deploy/deploy.sh')
}
} catch (err) {
currentBuild.result = "FAILED"
throw err
} finally {
notifyBuild(currentBuild.result)
}
}
/**
* Send notifications based on build status string
*/
def notifyBuild(String buildStatus = 'STARTED') {
// build status of null means successful
buildStatus = buildStatus ?: 'SUCCESS'
// Default values
def colorName = 'RED'
def colorCode = '#FF0000'
def subject = "${buildStatus}: Job '${env.JOB_NAME} [${env.BUILD_NUMBER}]'"
def summary = "${subject} (${env.BUILD_URL})"
def details = """<p>${buildStatus}: Job '${env.JOB_NAME} [${env.BUILD_NUMBER}]':</p>
<p>Check console output at "<a href='${env.BUILD_URL}'>${env.JOB_NAME} [${env.BUILD_NUMBER}]</a>"</p>"""
// Override default values based on build status
if (buildStatus == 'STARTED') {
color = 'YELLOW'
colorCode = '#FFFF00'
} else if (buildStatus == 'SUCCESS') {
color = 'GREEN'
colorCode = '#00FF00'
} else {
color = 'RED'
colorCode = '#FF0000'
}
// Send notifications
slackSend (color: colorCode, message: summary)
}