-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathJenkinsfile_NotUsed
94 lines (90 loc) · 2.99 KB
/
Jenkinsfile_NotUsed
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
91
92
93
94
def testReports = false
//stage 'Build'
node('once-ui-pod') {
try {
def branchName = env.CHANGE_TARGET
if (branchName == null) {
branchName = env.BRANCH_NAME
}
def parseChannelAndEnv = getEnvironment(branchName)
def environment = parseChannelAndEnv[0]
container('once-ui'){
stage('Checkout') {
checkout scm
}
}
container('once-ui'){
stage('Test') {
env.NODE_ENV = "test"
sh "npm ci"
sh "npm run prettier"
sh "npm run lint"
sh "npm run test"
testReports = true
}
}
container('once-ui'){
stage('Docker Image Build') {
println environment
def registry_url = "http://dockeronce.azurecr.io/" // Docker Hub
def docker_creds_id = "dockeronce" // name of the Jenkins Credentials ID
if( environment!= null ) {
docker.withRegistry("${registry_url}", "${docker_creds_id}") {
echo "Building docker image with docker.build(once-ui:qa)"
image = docker.build("once-ui:qa")
stage("Docker Image Push") {
image.push()
}
}
}
}
}
} catch (e) {
currentBuild.result = "FAILED"
throw e
} finally {
if(testReports){
junit 'reports/**/*.xml'
}
notifyBuild(currentBuild.result, env.channel)
cleanWs()
}
}
def getEnvironment(String branchName) {
def environment
def isTeamBranch = (branchName ==~ /team\/.*/)
if (isTeamBranch) {
environment = branchName.replace("team/", "")
return [environment, "$environment-builds"]
} else if (branchName == "master") {
return ["prod", "jenkins"]
} else if (branchName == "qa") {
return ["qa", "jenkins"]
} else {
return [null];
}
}
def notifyBuild(String buildStatus = 'STARTED', String channel = "jenkins") {
// build status of null means successful
buildStatus = buildStatus ?: 'SUCCESSFUL'
// Default values
def colorName = 'RED'
def colorCode = '#FF0000'
def subject = "${env.JOB_NAME} [${env.BUILD_NUMBER}]"
def summary = "${buildStatus}: Job <${env.BUILD_URL}|${subject}>"
def details = """<p>STARTED: Job '${env.JOB_NAME} [${env.BUILD_NUMBER}]':</p>
<p> Check console output at & QUOT; < a href = '${env.BUILD_URL}'>${env.JOB_NAME}[${env.BUILD_NUMBER}]</a>"</p >"""
// Override default values based on build status
if (buildStatus == 'STARTED' || buildStatus == 'UNSTABLE') {
color = 'YELLOW'
colorCode = '#FFFF00'
} else if (buildStatus == 'SUCCESSFUL' || buildStatus == 'Success' || buildStatus == 'SUCCESS') {
color = 'GREEN'
colorCode = '#00FF00'
} else {
color = 'RED'
colorCode = '#FF0000'
}
// Send notifications
slackSend(channel: "#$channel", color: colorCode, message: summary)
}