forked from as-ideas/oil
-
Notifications
You must be signed in to change notification settings - Fork 0
/
JenkinsFileBuildAndDeployIntegration
97 lines (81 loc) · 2.53 KB
/
JenkinsFileBuildAndDeployIntegration
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
95
#!groovy
def sendPerSlack(color, status) {
def committerEmail = sh(
script: 'git --no-pager show -s --format=\'%an\'',
returnStdout: true
).trim()
def buildUser = wrap([$class: 'BuildUser']) {
sh(
script: 'echo ${BUILD_USER}',
returnStdout: true
)
}
slackSend color: color, message: "${status}: Job '${env.JOB_NAME} [${env.BUILD_NUMBER}]' (${env.BUILD_URL}) - Committer: ${committerEmail} - Job started by: ${buildUser}"
}
def repositoryUrl
node {
//Setup nodeJS from nodeJS Jenkins Plugin
env.NODEJS_HOME = "${tool 'NodeJs 11.14.0'}"
env.PATH = "${env.NODEJS_HOME}/bin:${env.PATH}"
try {
stage('Cleanup workspace') {
deleteDir()
}
stage('Checkout') {
checkout scm
repositoryUrl = sh(returnStdout: true, script: 'git config remote.origin.url').trim().substring('https://'.length())
sendPerSlack('#000000', "STARTED")
}
stage('Install dependencies') {
sh "npm i"
}
stage('Build') {
wrap([$class: 'AnsiColorBuildWrapper', 'colorMapName': 'xterm']) {
sh "npm run build"
}
}
stage('Test') {
wrap([$class: 'AnsiColorBuildWrapper', 'colorMapName': 'xterm']) {
sh "npm run test"
}
}
stage('Deploy integration') {
if (env.BRANCH_NAME ==~ /(master)/) {
parallel 'host1': {
stage('host1') {
sh "git push -f https://git.heroku.com/oil-integration-host1.git HEAD:master"
}
}, 'host2': {
stage('host2') {
sh "git push -f https://git.heroku.com/oil-integration-host2.git HEAD:master"
}
}
}
}
stage('E2E-Test') {
if (env.BRANCH_NAME ==~ /(master)/) {
wrap([$class: 'AnsiColorBuildWrapper', 'colorMapName': 'xterm']) {
sh "npm run test:selenium"
}
}
}
stage('Create Git Tag') {
if (env.BRANCH_NAME ==~ /(master)/) {
withCredentials([usernamePassword(credentialsId: '52e3bd5e-ef78-428f-921e-3f57e5e06fd7', passwordVariable: 'GIT_PASSWORD', usernameVariable: 'GIT_USERNAME')]) {
sh "git tag -a 'build-oil-${env.BUILD_NUMBER}' -m 'Successful build-oil-${env.BUILD_NUMBER}'"
sh "git push https://\${GIT_USERNAME}:\${GIT_PASSWORD}@${repositoryUrl} --tags"
}
}
}
currentBuild.result = 'SUCCESS'
} catch (e) {
currentBuild.result = 'FAILED'
throw e
} finally {
if (currentBuild.result == 'SUCCESS') {
sendPerSlack('#00FF00', "SUCCESSFUL")
} else {
sendPerSlack('#FF0000', "FAILED")
}
}
}