-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathJenkinsfile
188 lines (184 loc) · 5.69 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
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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
#!groovy
def slackChannel = '#amf-jenkins'
def failedStage = ""
def color = '#FF8C00'
def headerFlavour = "WARNING"
pipeline {
agent {
dockerfile true
}
environment {
NEXUS = credentials('exchange-nexus')
NEXUSIQ = credentials('nexus-iq')
GITHUB_ORG = 'aml-org'
GITHUB_REPO = 'amf'
}
stages {
stage('Test') {
steps {
wrap([$class: 'AnsiColorBuildWrapper', 'colorMapName': 'XTerm']) {
script {
try{
sh 'sbt -mem 4096 -Dfile.encoding=UTF-8 clean coverage test coverageReport'
} catch (ignored) {
failedStage = failedStage + " TEST "
unstable "Failed tests"
}
}
}
}
}
stage('Coverage') {
when {
anyOf {
branch 'master'
branch 'develop'
}
}
steps {
wrap([$class: 'AnsiColorBuildWrapper', 'colorMapName': 'XTerm']) {
withCredentials([[$class: 'UsernamePasswordMultiBinding', credentialsId: 'sonarqube-official', passwordVariable: 'SONAR_SERVER_TOKEN', usernameVariable: 'SONAR_SERVER_URL']]) {
script {
try {
if (failedStage.isEmpty()) {
sh 'sbt -Dsonar.host.url=${SONAR_SERVER_URL} sonarScan'
}
} catch (ignored) {
failedStage = failedStage + " COVERAGE "
unstable "Failed coverage"
}
}
}
}
}
}
stage('Publish') {
when {
anyOf {
branch 'master'
branch 'develop'
branch 'release/*'
}
}
steps {
wrap([$class: 'AnsiColorBuildWrapper', 'colorMapName': 'XTerm']) {
script {
try{
if (failedStage.isEmpty()) {
sh '''
echo "about to publish in sbt"
sbt publish
echo "sbt publishing successful"
'''
}
} catch(ignored) {
failedStage = failedStage + " PUBLISH "
unstable "Failed publication"
}
}
}
}
}
stage('Tag version') {
when {
anyOf {
branch 'master'
branch 'support/*'
}
}
steps {
withCredentials([[$class: 'UsernamePasswordMultiBinding', credentialsId: 'github-salt', passwordVariable: 'GITHUB_PASS', usernameVariable: 'GITHUB_USER']]) {
script {
try{
if (failedStage.isEmpty()) {
sh '''#!/bin/bash
echo "about to tag the commit with the new version:"
version=$(sbt version | tail -n 1 | grep -o '[0-9].[0-9].[0-9].*')
url="https://${GITHUB_USER}:${GITHUB_PASS}@github.com/${GITHUB_ORG}/${GITHUB_REPO}"
git tag $version
git push $url $version && echo "tagging successful"
'''
}
} catch(ignored) {
failedStage = failedStage + " TAGGING "
unstable "Failed publication"
}
}
}
}
}
stage('Nexus IQ') {
when {
anyOf {
branch 'develop'
}
}
steps {
wrap([$class: 'AnsiColorBuildWrapper', 'colorMapName': 'XTerm']) {
script {
try{
if (failedStage.isEmpty()){
sh './gradlew nexusIq'
}
} catch(ignored) {
failedStage = failedStage + " NEXUSIQ "
unstable "Failed Nexus IQ"
}
}
}
}
}
stage('Trigger amf projects') {
when {
branch 'develop'
}
steps {
script {
try {
if (failedStage.isEmpty()){
echo "Starting TCKutor Applications/AMF/amfTCKutor/master"
build job: 'application/AMF/amfTCKutor/master', wait: false
echo "Starting Amf Examples Applications/AMF/amfexamples/master"
build job: 'application/AMF/amf-examples/snapshot', wait: false
echo "Starting Amf Interface Tests Applications/AMF/amfinterfacetests/master"
build job: 'application/AMF/amf-interface-tests/master', wait: false
if (env.BRANCH_NAME == 'master' || env.BRANCH_NAME == 'develop') {
echo "Starting Amf Metadata Tests Applications/AMF/amf-metadata/master"
build job: "application/AMF/amf-metadata/${env.BRANCH_NAME}", wait: false
} else {
echo "Skipping Amf Metadata Tests Build Trigger as env.BRANCH_NAME is not master or develop"
}
}
} catch(ignored) {
failedStage = failedStage + " TCKUTOR "
unstable "Failed TCKUTOR job trigger"
}
}
}
}
stage("Report to Slack") {
when {
anyOf {
branch 'master'
branch 'develop'
}
}
steps {
script {
if (!failedStage.isEmpty()) {
if (env.BRANCH_NAME == 'master') {
color = '#FF0000'
headerFlavour = "RED ALERT"
} else if (env.BRANCH_NAME == 'devel') {
color = '#FFD700'
}
slackSend color: color, channel: "${slackChannel}", message: ":alert: ${headerFlavour}! :alert: Build failed!. \n\tBranch: ${env.BRANCH_NAME}\n\tStage:${failedStage}\n(See ${env.BUILD_URL})\n"
currentBuild.status = "FAILURE"
} else if (env.BRANCH_NAME == 'master') {
slackSend color: '#00FF00', channel: "${slackChannel}", message: ":ok_hand: Master Publish OK! :ok_hand:"
}
}
}
}
}
}