-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
109 lines (99 loc) · 4.46 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
pipeline {
environment {
ARTIFACTORY_URL = credentials('ARTIFACTORY_URL')
}
agent {
label 'build'
}
tools {
gradle "gradle-7.2"
jdk 'openjdk15'
}
stages {
stage ('Build Lambdas') {
steps {
withCredentials([usernamePassword(credentialsId: 'artifactoryuserpass', usernameVariable: 'ARTIFACTORY_USER', passwordVariable: 'ARTIFACTORY_PASSWORD')]) {
sh './gradlew -b build.gradle '
}
}
}
stage ('Test Lambdas') {
steps {
withCredentials([usernamePassword(credentialsId: 'artifactoryuserpass', usernameVariable: 'ARTIFACTORY_USER', passwordVariable: 'ARTIFACTORY_PASSWORD')]) {
sh './gradlew clean test --info -b build.gradle'
}
}
}
stage ('Build Jars') {
steps {
withCredentials([usernamePassword(credentialsId: 'artifactoryuserpass', usernameVariable: 'ARTIFACTORY_USER', passwordVariable: 'ARTIFACTORY_PASSWORD')]) {
sh './gradlew buildZip --info -b build.gradle'
}
}
}
stage('SonarQube Analysis') {
steps {
withCredentials([usernamePassword(credentialsId: 'artifactoryuserpass', usernameVariable: 'ARTIFACTORY_USER', passwordVariable: 'ARTIFACTORY_PASSWORD')]) {
// Automatically saves the an id for the SonarQube build
withSonarQubeEnv('CMSSonar') {
sh './gradlew sonarqube -Dsonar.projectKey=ab2d-lambdas -Dsonar.host.url=https://sonarqube.cloud.cms.gov'
}
}
}
}
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 ('SBOM') {
steps {
withCredentials([usernamePassword(credentialsId: 'artifactoryuserpass', usernameVariable: 'ARTIFACTORY_USER', passwordVariable: 'ARTIFACTORY_PASSWORD')]) {
sh './gradlew cyclonedxBom --info -b build.gradle'
}
}
}
stage ('Publish Lambdas') {
//when {
// branch 'main'
// }
steps {
withCredentials([usernamePassword(credentialsId: 'artifactoryuserpass', usernameVariable: 'ARTIFACTORY_USER', passwordVariable: 'ARTIFACTORY_PASSWORD')]) {
script {
def deployScript = '';
//Calls a gradle task to check if the version of each build has already been deployed
//Each build is broken up by '''.
def versionPublishedList = sh(
script: './gradlew -q lookForArtifacts',
returnStdout: true
).trim().split("'''")
//First value represents the build name and the second value is if the version is already deployed.
for (int i = 1; i < versionPublishedList.size(); i++) {
def artifactoryInfo = versionPublishedList[i].split(":")
if (artifactoryInfo[1] == 'false') {
echo "Deploying ${artifactoryInfo[0]}"
deployScript += "${artifactoryInfo[0]}:artifactoryPublish "
}
}
//deployScript represents what we are publishing. Insert it into the gradle command to do the publishing.
//ex. ab2d-fhir:artifactoryPublish"
//If nothing is there, skip publishing
if(deployScript != '') {
sh "./gradlew ${deployScript} -b build.gradle"
}
def buildVersion = sh(
script: "./gradlew properties -q | grep \"version:\" | awk '{print \$2}'",
returnStdout: true
)
env.buildVersion = buildVersion
}
}
}
}
}
}