-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathJenkinsfile
More file actions
158 lines (148 loc) · 5 KB
/
Jenkinsfile
File metadata and controls
158 lines (148 loc) · 5 KB
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
pipeline {
agent {
label 'windows'
}
environment {
DlsRefactor_ConnectionStrings__UnitTestConnection = credentials('uar-ci-db-connection-string')
DlsRefactor_LearningHubOpenAPIKey = credentials('ci-learning-hub-open-api-key')
}
stages {
stage('Checkout') {
steps {
checkout scm
}
}
stage('Build') {
steps {
bat "dotnet build DigitalLearningSolutions.sln"
}
}
stage('TS Build') {
steps {
dir("DigitalLearningSolutions.Web/") {
nodejs(nodeJSInstallationName: 'NodeJS-16') {
bat "yarn install --frozen-lockfile"
bat "yarn build"
}
}
}
}
stage('TS Lint') {
steps {
dir ("DigitalLearningSolutions.Web/") {
nodejs(nodeJSInstallationName: 'NodeJS-16') {
bat "yarn lint"
}
}
}
}
stage('Web Tests') {
steps {
bat "dotnet test DigitalLearningSolutions.Web.Tests"
}
}
stage('Data Tests') {
steps {
bat "dotnet test DigitalLearningSolutions.Data.Tests"
}
}
stage('Integration Tests') {
environment {
DlsRefactor_ConnectionStrings__DefaultConnection = credentials('uar-ci-db-connection-string')
}
steps {
bat "dotnet test DigitalLearningSolutions.Web.IntegrationTests"
}
}
stage('Automated UI Tests') {
environment {
DlsRefactor_ConnectionStrings__DefaultConnection = credentials('uar-ci-db-connection-string')
}
steps {
bat "dotnet test DigitalLearningSolutions.Web.AutomatedUiTests"
}
}
stage('TS Tests') {
steps {
dir ("DigitalLearningSolutions.Web/") {
nodejs(nodeJSInstallationName: 'NodeJS-16') {
bat "yarn test"
}
}
}
}
stage('Deploy to UAR test') {
when {
branch 'uar-test'
}
steps {
withCredentials([string(credentialsId: 'deploy-test-password', variable: 'PASSWORD')]) {
nodejs(nodeJSInstallationName: 'NodeJS-16') {
bat "dotnet publish DigitalLearningSolutions.Web/DigitalLearningSolutions.Web.csproj /p:PublishProfile=DigitalLearningSolutions.Web/Properties/PublishProfiles/PublishToUARTest.pubxml /p:Password=$PASSWORD /p:AllowUntrustedCertificate=True"
}
}
}
}
}
post {
failure {
sendFailureMessages(":red_circle: Build failed", "danger")
}
success {
sendSlackMessageToTeamChannel(":excellent: Build succeeded", "good")
}
}
}
def sendFailureMessages(message, color) {
sendSlackMessageToTeamChannel(message, color)
sendSlackDirectMessage(message, color)
}
def sendSlackMessageToTeamChannel(message, color) {
sendSlackNotificationToChannel("#hee-notifications", message, color)
}
def sendSlackNotificationToChannel(channel, message, color) {
withCredentials([string(credentialsId: 'slack-token', variable: 'SLACKTOKEN')]) {
slackSend teamDomain: "softwire",
channel: channel,
token: "$SLACKTOKEN",
message: "*$message* - ${env.JOB_NAME} ${env.BUILD_NUMBER} (<${env.BUILD_URL}|Open>)",
color: color
}
}
def sendSlackDirectMessage(message, color) {
def emailAddress = getCommitterEmailAddress()
def slackUser = getSlackUserByEmailAddress(emailAddress)
sendSlackNotificationToChannel(slackUser, message, color)
}
def getCommitterEmailAddress() {
if (steps.isUnix()) {
return steps.sh (
script: 'git --no-pager show -s --format=\'%ae\'',
returnStdout: true
).trim()
} else {
def commitDetails = steps.bat (
script: 'git --no-pager show --no-patch --format=%%ae',
returnStdout: true
)
return extractEmailAddressFromCommitDetails(commitDetails)
}
}
def extractEmailAddressFromCommitDetails(commitDetails) {
def tokens = commitDetails.tokenize('\n')
return tokens.last().trim()
}
def getSlackUserByEmailAddress(emailAddress) {
return getSlackUsers()[emailAddress.toLowerCase()] ?: '@SteJac'
}
def getSlackUsers() {
return [
'david.may-miller@softwire.com':'@DavMay',
'jonathan.bloxsom@softwire.com':'@JonBlo',
'stephen.jackson@softwire.com':'@SteJac',
'olivia.zorn@softwire.com':'@OliZor',
'simon.brent@softwire.com':'@SimBre',
'vlad.nicolaescu@softwire.com':'@VlaNic',
'kevin.whittaker@hee.nhs.uk':'@KevWhi',
]
}