-
Notifications
You must be signed in to change notification settings - Fork 1
/
Jenkinsfile
129 lines (110 loc) · 4.89 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
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
def branchSuffix() {
return env.BRANCH_NAME == 'master' ? '' : '-' + env.BRANCH_NAME.replaceAll(/[^0-9A-Za-z-]+/, '-')
}
def fullVersion() {
return env.VERSION + '.' + env.BUILD_NUMBER + branchSuffix()
}
pipeline {
agent {
docker {
image 'jmesserli/oc-docker-build-container'
args '-v /var/run/docker.sock:/var/run/docker.sock -v /opt/jenkins-agent/persist/yarn:/root/yarn-cache'
}
}
options {
buildDiscarder(logRotator(numToKeepStr: '20'))
}
environment {
VERSION = readFile('VERSION')
}
stages {
stage('Prepare') {
steps {
sh 'chmod +x gradlew'
}
}
stage('Build') {
steps {
parallel(
"Build Backend": {
sh './gradlew clean :backend:assemble :backend:configurationZip --stacktrace --info'
},
"Build Frontend": {
sh './gradlew :frontend:setCacheFolderCI :frontend:assemble --stacktrace --info'
}
)
}
post {
success {
archiveArtifacts 'backend/build/libs/*.jar'
}
failure {
slackSend color: 'warning',
message: ":negative_squared_cross_mark: Build for ${currentBuild.fullDisplayName} is failing"
}
}
}
stage('Test') {
environment {
CODECOV_TOKEN = credentials('codecov-token')
}
steps {
parallel(
"Test Backend": {
sh './gradlew :backend:check --stacktrace --info'
sh "#!/bin/bash\ncd backend && bash <(curl -s https://codecov.io/bash) -cF backend"
},
"Test Frontend": {
sh './gradlew :frontend:test --stacktrace --info'
sh "#!/bin/bash\ncd frontend && bash <(curl -s https://codecov.io/bash) -cF frontend"
}
)
}
post {
always {
junit '**/test-results/**/*.xml'
}
success {
slackSend color: 'good',
message: ":heavy_check_mark: Tests for ${currentBuild.fullDisplayName} have passed"
}
failure {
slackSend color: 'warning',
message: ":negative_squared_cross_mark: Tests for ${currentBuild.fullDisplayName} are failing"
}
}
}
stage('Docker & Octopus Release') {
when { anyOf { branch 'develop'; branch 'master' } }
environment {
DOCKER = credentials('docker-deploy')
FULL_VERSION = fullVersion()
OCTOPUS_API_KEY = credentials('octopus-deploy')
}
steps {
sh 'docker login -u "$DOCKER_USR" -p "$DOCKER_PSW" docker.pegnu.cloud:443'
sh 'docker build -t docker.pegnu.cloud:443/outcobra-backend:$FULL_VERSION -t docker.pegnu.cloud:443/outcobra-backend:latest backend'
sh 'docker build -t docker.pegnu.cloud:443/outcobra-frontend:$FULL_VERSION -t docker.pegnu.cloud:443/outcobra-frontend:latest frontend'
sh 'docker push docker.pegnu.cloud:443/outcobra-frontend:$FULL_VERSION && docker push docker.pegnu.cloud:443/outcobra-frontend:latest'
sh 'docker push docker.pegnu.cloud:443/outcobra-backend:$FULL_VERSION && docker push docker.pegnu.cloud:443/outcobra-backend:latest'
sh '/opt/octo/Octo push --package backend/build/distributions/outcobra-configuration.$FULL_VERSION.zip --replace-existing --server https://deploy.pegnu.cloud --apiKey $OCTOPUS_API_KEY'
sh '/opt/octo/Octo create-release --project "Outstanding Cobra" --version $FULL_VERSION --package outcobra-configuration:$FULL_VERSION --package outcobra-frontend:$FULL_VERSION --package outcobra-backend:$FULL_VERSION --package mariadb:10 --server https://deploy.pegnu.cloud --apiKey $OCTOPUS_API_KEY'
}
post {
success {
slackSend color: 'good',
message: ":rocket: Build #${env.BUILD_NUMBER} successful and released to [Octopus](https://deploy.pegnu.cloud/app#/projects/outstanding-cobra/releases/${env.FULL_VERSION})"
}
failure {
slackSend color: 'danger',
message: ":heavy_exclamation_mark: Releasing #${env.BUILD_NUMBER} (${env.FULL_VERSION}) failed!"
}
}
}
}
post {
always {
deleteDir()
}
}
}