-
Notifications
You must be signed in to change notification settings - Fork 1
/
Jenkinsfile
100 lines (98 loc) · 3.3 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
91
92
93
94
95
96
97
98
99
100
pipeline {
environment {
NTBS_BUILD = "build-${env.BUILD_ID}-${env.GIT_COMMIT.substring(0, 6)}"
}
agent { label 'linux' }
stages {
stage('run unit tests') {
steps {
script {
docker.image('mcr.microsoft.com/dotnet/core/sdk:2.2').inside {
sh(script: '''
# Workaround from https://stackoverflow.com/a/57212491/2363767
export DOTNET_CLI_HOME="/tmp/DOTNET_CLI_HOME"
cd ntbs-service-unit-tests
echo "Running service unit tests"
dotnet test
cd ../EFAuditer-tests
echo "Running EFAuditer unit tests"
dotnet test
''')
}
}
}
}
stage('run integration tests') {
steps {
script {
docker.image('mcr.microsoft.com/dotnet/core/sdk:2.2').inside {
sh(script: '''
# Workaround from https://stackoverflow.com/a/57212491/2363767
export DOTNET_CLI_HOME="/tmp/DOTNET_CLI_HOME"
cd ntbs-integration-tests
echo "Running integration tests"
dotnet test
''')
}
}
}
}
stage('run ui tests') {
steps {
script {
docker.build("ntbs-service-ui-tests:${NTBS_BUILD}", "-f Dockerfile-uitests --build-arg CACHEBUST=${NTBS_BUILD} .").inside {
sh(script: '''
# We would like to run the actual tests in here, but an issue with jenkins means we do that within the docker build
# See Dockerfile-uitests for details.
echo "ui tests complete"
''')
}
}
}
}
stage('build and publish image') {
steps {
script {
docker.withRegistry('https://ntbscontainerregistry.azurecr.io', 'ntbs-registery-credentials') {
withCredentials([string(credentialsId: 'sentry-auth-token', variable: 'SENTRY_AUTH_TOKEN')]) {
ntbsImage = docker.build("ntbs-service:${NTBS_BUILD}", "--build-arg RELEASE=${NTBS_BUILD} --build-arg SENTRY_AUTH_TOKEN=${SENTRY_AUTH_TOKEN} .")
echo "Uploading build image ${NTBS_BUILD}"
ntbsImage.push()
echo "Uploading latest image"
ntbsImage.push("latest")
}
}
}
}
}
stage('deploy to int') {
steps {
script {
kubectl = docker.image('bitnami/kubectl')
kubectl.inside("--entrypoint=''") {
withCredentials([[$class: 'FileBinding', credentialsId: 'kubeconfig', variable: 'KUBECONFIG']]) {
sh "chmod +x ./scripts/release.sh"
sh "./scripts/release.sh int ${NTBS_BUILD}"
}
}
}
}
}
}
post {
success {
notifySlack(":green_heart: :computer: Build succeeded. New deployment on int: ${NTBS_BUILD}")
}
failure {
notifySlack(":red_circle: :computer: @here Build failed")
}
unstable {
notifySlack(":large_orange_diamond: :computer: Build unstable")
}
}
}
def notifySlack(message) {
withCredentials([string(credentialsId: 'slack-token', variable: 'SLACKTOKEN')]) {
slackSend teamDomain: "phe-ntbs", channel: "#dev-ci", token: "$SLACKTOKEN", message: "*${message}* - ${env.JOB_NAME} ${NTBS_BUILD} (<${env.BUILD_URL}|Open>)"
}
}