-
Notifications
You must be signed in to change notification settings - Fork 2
/
Jenkinsfile
227 lines (185 loc) · 9.01 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
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
pipeline {
environment {
OKTA_CLIENT_ID = credentials('OKTA_CLIENT_ID')
OKTA_CLIENT_PASSWORD = credentials('OKTA_CLIENT_PASSWORD')
SECONDARY_USER_OKTA_CLIENT_ID = credentials('SECONDARY_USER_OKTA_CLIENT_ID')
SECONDARY_USER_OKTA_CLIENT_PASSWORD = credentials('SECONDARY_USER_OKTA_CLIENT_PASSWORD')
// Get code climate id
CC_TEST_REPORTER_ID = credentials('CC_TEST_REPORTER_ID')
// Tell e2e test that it should override the docker compose it normally uses locally
// with docker-compose.jenkins.yml
E2E_ENVIRONMENT = 'CI'
AB2D_HOME="${WORKSPACE}/opt/ab2d"
// R4 V2 endpoints enabled
AB2D_V2_ENABLED = true
// Number of beneficiaries to search in each PatientClaimsProcessorImpl thread - Patient batch size
SEARCH_BENE_BATCH_SIZE=10
ARTIFACTORY_URL = credentials('ARTIFACTORY_URL')
AWS_DEFAULT_REGION = "us-east-1"
ECR_REPO_ENV_AWS_ACCOUNT_NUMBER = "777200079629"
}
agent {
label 'build'
}
tools {
maven 'maven-3.6.3'
jdk 'openjdk17'
}
stages {
stage('Create ab2d workspace directory and copy in keystore') {
steps {
sh '''
mkdir -p "$WORKSPACE/opt/ab2d"
'''
}
}
// Make sure codeclimate is present in the environment
stage('Download Code Coverage') {
steps {
sh '''
mkdir -p codeclimate
if [ ! -f ./codeclimate/cc-test-reporter ]; then
curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 \
> ./codeclimate/cc-test-reporter && chmod +x ./codeclimate/cc-test-reporter
fi
'''
}
}
stage('Clean maven') {
steps {
sh '''
mvn --version
echo $WORKSPACE
mvn -U clean
'''
}
}
stage('Package without tests - Create SBOM') {
steps {
withCredentials([usernamePassword(credentialsId: 'artifactoryuserpass', usernameVariable: 'ARTIFACTORY_USER', passwordVariable: 'ARTIFACTORY_PASSWORD')]) {
sh 'mvn -U package -s settings.xml -DskipTests -Dusername=${ARTIFACTORY_USER} -Dpassword=${ARTIFACTORY_PASSWORD} -Drepository_url=${ARTIFACTORY_URL}'
}
}
}
stage('Run unit and integration tests') {
steps {
withCredentials([usernamePassword(credentialsId: 'artifactoryuserpass', usernameVariable: 'ARTIFACTORY_USER', passwordVariable: 'ARTIFACTORY_PASSWORD')]) {
sh '''
export AB2D_EFS_MOUNT="${AB2D_HOME}"
mvn -s settings.xml -Dusername=${ARTIFACTORY_USER} -Dpassword=${ARTIFACTORY_PASSWORD} -Drepository_url=${ARTIFACTORY_URL} test -pl common,job,coverage,api,worker
'''
}
}
}
stage('Run e2e-bfd-test') {
steps {
withCredentials([file(credentialsId: 'SANDBOX_BFD_KEYSTORE', variable: 'SANDBOX_BFD_KEYSTORE'),
string(credentialsId: 'SANDBOX_BFD_KEYSTORE_PASSWORD', variable: 'AB2D_BFD_KEYSTORE_PASSWORD'),
usernamePassword(credentialsId: 'artifactoryuserpass', usernameVariable: 'ARTIFACTORY_USER', passwordVariable: 'ARTIFACTORY_PASSWORD')]) {
sh '''
export AB2D_BFD_KEYSTORE_LOCATION="$WORKSPACE/opt/ab2d/ab2d_bfd_keystore"
cp $SANDBOX_BFD_KEYSTORE $AB2D_BFD_KEYSTORE_LOCATION
test -f $AB2D_BFD_KEYSTORE_LOCATION && echo "created keystore file"
chmod 666 $AB2D_BFD_KEYSTORE_LOCATION
ls -la $AB2D_BFD_KEYSTORE_LOCATION
export AB2D_V2_ENABLED=true
mvn test -s settings.xml -pl e2e-bfd-test -am -Dtest=EndToEndBfdTests -DfailIfNoTests=false -Dusername=${ARTIFACTORY_USER} -Dpassword=${ARTIFACTORY_PASSWORD} -Drepository_url=${ARTIFACTORY_URL}
'''
}
}
}
stage('SonarQube Analysis') {
steps {
withCredentials([usernamePassword(credentialsId: 'artifactoryuserpass', usernameVariable: 'ARTIFACTORY_USER', passwordVariable: 'ARTIFACTORY_PASSWORD')]) {
git branch: 'main', credentialsId: 'GITHUB_AB2D_JENKINS_PAT', url: env.GIT_URL
git branch: env.BRANCH_NAME, credentialsId: 'GITHUB_AB2D_JENKINS_PAT', url: env.GIT_URL
// Automatically saves the an id for the SonarQube build
withSonarQubeEnv('CMSSonar') {
sh '''
mvn -s settings.xml sonar:sonar -Dsonar.projectKey=ab2d-project -DskipTests -Dusername=${ARTIFACTORY_USER} -Dpassword=${ARTIFACTORY_PASSWORD} -Drepository_url=${ARTIFACTORY_URL}
'''
}
}
}
}
// New Way in declarative pipeline
stage("Quality Gate") {
options {
timeout(time: 10, unit: 'MINUTES')
}
steps {
// Parameter indicates whether to set pipeline to UNSTABLE if Quality Gate fails
// true = set pipeline to UNSTABLE, false = don't
waitForQualityGate abortPipeline: true
}
}
stage('Run codeclimate tests') {
steps {
sh '''
export JACOCO_SOURCE_PATH=./api/src/main/java
./codeclimate/cc-test-reporter format-coverage ./api/target/site/jacoco/jacoco.xml --input-type jacoco -o codeclimate.api.json
export JACOCO_SOURCE_PATH=./common/src/main/java
./codeclimate/cc-test-reporter format-coverage ./common/target/site/jacoco/jacoco.xml --input-type jacoco -o codeclimate.common.json
export JACOCO_SOURCE_PATH=./job/src/main/java
./codeclimate/cc-test-reporter format-coverage ./job/target/site/jacoco/jacoco.xml --input-type jacoco -o codeclimate.job.json
export JACOCO_SOURCE_PATH=./coverage/src/main/java
./codeclimate/cc-test-reporter format-coverage ./coverage/target/site/jacoco/jacoco.xml --input-type jacoco -o codeclimate.coverage.json
export JACOCO_SOURCE_PATH=./worker/src/main/java
./codeclimate/cc-test-reporter format-coverage ./worker/target/site/jacoco/jacoco.xml --input-type jacoco -o codeclimate.worker.json
'''
}
}
stage('Cleanup - first pass of docker deletions part 1') {
steps {
catchError(buildResult: 'SUCCESS', stageResult: 'SUCCESS') {
sh '''
docker volume ls -qf dangling=true | xargs -I name docker volume rm name
docker ps -aq | xargs -I name docker rm --force name
'''
}
}
}
stage('Cleanup - first pass of docker deletions part 2') {
steps {
catchError(buildResult: 'SUCCESS', stageResult: 'SUCCESS') {
sh '''
docker images | grep _api | awk '{print $3}' | xargs -I name docker rmi --force name
docker images | grep _worker | awk '{print $3}' | xargs -I name docker rmi --force name
'''
}
}
}
stage('Cleanup - second pass of docker deletions') {
steps {
catchError(buildResult: 'SUCCESS', stageResult: 'SUCCESS') {
sh '''
docker volume ls -qf dangling=true | xargs -I name docker volume rm name
docker images | grep _api | awk '{print $3}' | xargs -I name docker rmi --force name
docker images | grep _worker | awk '{print $3}' | xargs -I name docker rmi --force name
'''
}
}
}
stage('Cleanup - delete all but the defaut docker networks') {
steps {
catchError(buildResult: 'SUCCESS', stageResult: 'SUCCESS') {
sh '''
# Delete all but the defaut docker networks
docker network ls | awk '{print $1, $2}' | grep -v " bridge" | grep -v " host" | grep -v " none" \
| grep -v "NETWORK ID" | awk '{print $1}' | xargs -I name docker network rm name
'''
}
}
}
}
post {
always {
script {
sh '''
rm -rf "$WORKSPACE/opt/ab2d" 2> /dev/null
rm -rf "$WORKSPACE/.m2/repository/gov/cms/ab2d" 2> /dev/null
'''
}
}
}
}