-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathJenkinsfile
153 lines (149 loc) · 4.88 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
#!groovy
@Library('amf-jenkins-library') _
import groovy.transform.Field
def SLACK_CHANNEL = '#amf-jenkins'
def PRODUCT_NAME = "amf-metadata"
def lastStage = ""
def color = '#FF8C00'
def headerFlavour = "WARNING"
def HAS_PUBLISHED_VOCABULARY = false
def HAS_PUBLISHED_TRANSFORM = false
pipeline {
options {
timeout(time: 30, unit: 'MINUTES')
ansiColor('xterm')
}
agent {
dockerfile {
registryCredentialsId 'dockerhub-pro-credentials'
registryCredentialsId 'github-salt'
registryUrl 'https://ghcr.io'
}
}
environment {
NEXUS = credentials('exchange-nexus')
NEXUSIQ = credentials('nexus-iq')
GITHUB_ORG = 'aml-org'
GITHUB_REPO = 'amf-metadata'
BUILD_NUMBER = "${env.BUILD_NUMBER}"
BRANCH_NAME = "${env.BRANCH_NAME}"
CURRENT_VERSION = sh(script: "cat dependencies.properties | grep \"version\" | cut -d '=' -f 2", returnStdout: true)
}
stages {
stage('Test') {
steps {
script {
lastStage = env.STAGE_NAME
sh 'sbt -mem 4096 -Dfile.encoding=UTF-8 clean coverage test coverageAggregate'
}
}
}
stage('Coverage') {
when {
anyOf {
branch 'master'
branch 'develop'
}
}
steps {
withCredentials([[$class: 'UsernamePasswordMultiBinding', credentialsId: 'sf-sonarqube-official', passwordVariable: 'SONAR_SERVER_TOKEN', usernameVariable: 'SONAR_SERVER_URL']]) {
script {
lastStage = env.STAGE_NAME
sh 'sbt -Dsonar.host.url=${SONAR_SERVER_URL} -Dsonar.login=${SONAR_SERVER_TOKEN} sonarScan'
}
}
}
}
stage('Publish Vocabulary Artifact') {
when {
anyOf {
branch 'master'
branch 'develop'
}
}
steps {
script {
lastStage = env.STAGE_NAME
sh '''
echo "about to publish in sbt"
sbt vocabulary/publish && echo "sbt publishing of amf-vocabulary successful"
'''
HAS_PUBLISHED_VOCABULARY = true
}
}
}
stage('Publish Transform Artifact') {
when {
anyOf {
branch 'master'
branch 'develop'
}
}
steps {
script {
lastStage = env.STAGE_NAME
sh '''
echo "about to publish amf-transform in sbt"
sbt transform/publish && echo "sbt publishing of amf-transform successful"
'''
HAS_PUBLISHED_TRANSFORM = true
}
}
}
stage('Tag published artifacts') {
when {
anyOf {
branch 'master'
}
}
steps {
withCredentials([[$class: 'UsernamePasswordMultiBinding', credentialsId: 'github-salt', passwordVariable: 'GITHUB_PASS', usernameVariable: 'GITHUB_USER']]) {
script {
try {
if (HAS_PUBLISHED_TRANSFORM) {
String tag = getNextTag("transform")
tagCommitToGithub(tag)
}
if (HAS_PUBLISHED_VOCABULARY) {
String tag = getNextTag("vocabulary")
tagCommitToGithub(tag)
}
} catch (ignored) {
failedStage = failedStage + " TAGGING "
unstable "Failed tagging"
}
}
}
}
}
stage('Nexus IQ') {
when {
anyOf {
branch 'master'
branch 'develop'
}
}
steps {
script {
lastStage = env.STAGE_NAME
sh '''
export JAVA_HOME=/opt/java/openjdk17
./gradlew nexusIq
'''
}
}
}
}
post {
unsuccessful {
failureSlackNotify(lastStage, SLACK_CHANNEL, PRODUCT_NAME)
}
success {
successSlackNotify(SLACK_CHANNEL, PRODUCT_NAME)
}
}
}
String getNextTag(String artifact) {
String semver = sbtArtifactVersion(artifact)
return "$artifact/$semver"
}