-
Notifications
You must be signed in to change notification settings - Fork 2
/
Jenkinsfile
90 lines (79 loc) · 3.15 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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#!groovy
node('ace-jenkins-slave') {
timestamps {
notifyBuild('STARTED')
try {
withCredentials([[$class: 'UsernamePasswordMultiBinding', credentialsId: 'NEXUS', usernameVariable: 'NEXUS_USERNAME', passwordVariable: 'NEXUS_PASSWORD'], [$class: 'UsernamePasswordMultiBinding', credentialsId: 'sonar', usernameVariable: 'SONAR_USERNAME', passwordVariable: 'SONAR_PASS']]) {
stage('checkout') {
checkout scm
}
sh "git rev-parse --short HEAD > .git/commit-id"
def commit_id = readFile('.git/commit-id')
def branchName = env.BRANCH_NAME
def tag = tagName(branchName)
stage('build for Comcast') {
sh "DOCKER_TAG=${tag} make build"
}
stage('build chart') {
sh "make chart-build"
}
if (shouldPush(branchName)) {
stage('push for Comcast') {
sh "DOCKER_TAG=${tag} make push"
}
stage('push chart') {
withCredentials([[$class: 'UsernamePasswordMultiBinding', credentialsId: 'jenkins-ci-comcast-github', usernameVariable: 'GITHUB_USER', passwordVariable: 'GITHUB_PASSWORD']]) {
sh "GITHUB_USER=${GITHUB_USER} GITHUB_PASSWORD=${GITHUB_PASSWORD} TAG_NAME=${tag} make chart-push"
}
}
}
if (shouldTag(branchName)) {
stage('tag') {
withCredentials([[$class: 'UsernamePasswordMultiBinding', credentialsId: 'jenkins-ci-comcast-github', usernameVariable: 'GITHUB_USER', passwordVariable: 'GITHUB_PASSWORD']]) {
sh "GITHUB_USER=${GITHUB_USER} GITHUB_PASSWORD=${GITHUB_PASSWORD} TAG_NAME=${tag} make tag"
}
}
}
}
} catch (Exception e) {
currentBuild.result = "FAILED"
throw e
} finally {
notifyBuild(currentBuild.result)
deleteDir()
}
}
}
def tagName(branchName) {
def versionPrefix = branchName
def versionSuffix = ".${env.BUILD_NUMBER}"
if (branchName == 'master') {
return "latest"
} else {
return "${versionPrefix}${versionSuffix}"
}
}
def shouldTag(branchName) {
branchName =~ /^(\d+\.)+(\d+)$/
}
def shouldPush(branchName) {
branchName == "master" || branchName =~ /^(\d+\.)+(\d+)$/
}
def notifyBuild(String buildStatus) {
//build status of null means successful
buildStatus = buildStatus ?: 'SUCCESSFUL'
// Override default values based on build status
if (buildStatus == 'STARTED') {
color = 'YELLOW'
colorCode = '#FFFF00'
} else if (buildStatus == 'SUCCESSFUL') {
color = 'GREEN'
colorCode = '#00FF00'
} else {
color = 'RED'
colorCode = '#FF0000'
}
def details = """*${buildStatus}: Job ${env.JOB_NAME} [${env.BUILD_NUMBER}]:*
Check console output at ${env.BUILD_URL}/console"""
slackSend(color: colorCode, message: details)
}