-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
106 lines (96 loc) · 4.3 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
pipeline {
environment {
ARTIFACTORY_URL = credentials('ARTIFACTORY_URL')
}
agent {
label 'build'
}
tools {
gradle "gradle-7.2"
jdk 'openjdk17'
}
stages {
stage ('Build Libraries') {
steps {
withCredentials([usernamePassword(credentialsId: 'artifactoryuserpass', usernameVariable: 'ARTIFACTORY_USER', passwordVariable: 'ARTIFACTORY_PASSWORD')]) {
sh 'gradle -b build.gradle'
}
}
}
stage ('Test Libraries') {
steps {
withCredentials([usernamePassword(credentialsId: 'artifactoryuserpass', usernameVariable: 'ARTIFACTORY_USER', passwordVariable: 'ARTIFACTORY_PASSWORD')]) {
sh 'gradle clean test --info -b build.gradle'
}
}
}
stage ('Build Jars') {
steps {
withCredentials([usernamePassword(credentialsId: 'artifactoryuserpass', usernameVariable: 'ARTIFACTORY_USER', passwordVariable: 'ARTIFACTORY_PASSWORD')]) {
sh 'gradle jar --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 'gradle sonarqube -Dsonar.projectKey=ab2d-lib-project -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("Generate SBOM") {
steps {
withCredentials([usernamePassword(credentialsId: 'artifactoryuserpass', usernameVariable: 'ARTIFACTORY_USER', passwordVariable: 'ARTIFACTORY_PASSWORD')]) {
sh 'gradle cyclonedxBom'
}
}
}
stage ('Publish Libraries') {
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 '''.
//Example: '''ab2d-filters:true'''fhir:false
def versionPublishedList = sh(
script: 'gradle -q lookForArtifacts',
returnStdout: true
).trim().split("'''")
//versionPublishedList ex: [ab2d-filters:true,fhir:false]
//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 "gradle ${deployScript} -b build.gradle"
}
}
}
}
}
}
}