-
Notifications
You must be signed in to change notification settings - Fork 45
/
Copy pathJenkinsfile
157 lines (155 loc) · 5.71 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
def buildNumber = env.BUILD_NUMBER as int
if (buildNumber > 1) milestone(buildNumber - 1)
milestone(buildNumber)
pipeline {
options { buildDiscarder(logRotator(numToKeepStr: '50')) }
environment {
SPRING_ACTIVE_PROFILE = "test"
}
agent {
kubernetes {
cloud 'ocp-c1'
label 'swatch-17-kubedock-2023-12-06' // this value + unique identifier becomes the pod name
idleMinutes 5 // how long the pod will live after no jobs have run on it
defaultContainer 'openjdk17'
yaml """
apiVersion: v1
kind: Pod
spec:
containers:
- name: kubedock
image: quay.io/cloudservices/kubedock:latest
imagePullPolicy: Always
tty: true
args:
- server
- --port-forward
# Verbosity level which is helpful to troubleshot issues when starting up containers
- -v
- 10
- name: openjdk17
image: registry.access.redhat.com/ubi9/openjdk-17-runtime
command:
- sleep
tty: true
args:
- 99d
resources:
requests:
memory: "2Gi"
cpu: "2"
limits:
memory: "6Gi"
cpu: "6"
env:
- name: DOCKER_HOST
value: tcp://127.0.0.1:2475
"""
}
}
stages {
stage('Verify PR ok to test') {
when {
beforeInput true
expression { env.CHANGE_FORK }
not {
anyOf {
// Kevin Howell
changeRequest author: "kahowell"
// Lindsey Burnett
changeRequest author: "lindseyburnett"
// Alex Wood
changeRequest author: "awood"
// Michael Stead
changeRequest author: "mstead"
// Kevin Flaherty
changeRequest author: "kflahert"
// Barnaby Court
changeRequest author: "barnabycourt"
// Nikhil Kathole
changeRequest author: "ntkathole"
// Jose Carvajal
changeRequest author: "Sgitario"
// Kartik Shah
changeRequest author: "kartikshahc"
// Vanessa Busch
changeRequest author: "vbusch"
// William Poteat
changeRequest author: "wottop"
// Ryan Himmelwright
changeRequest author: "himmAllRight"
// Trayvon McKnight
changeRequest author: "TrayvonMcKnight"
// Lisa Walker
changeRequest author: "liwalker-rh"
//Diego Maranhão
changeRequest author: "diegomaranhao"
//Aurobinda Nayak
changeRequest author: "Aurobinda55"
//Marek Musil
changeRequest author: "mmusil"
}
}
}
steps {
input 'ok to test?'
}
}
stage('Build/Test/Lint') {
steps {
// The build task includes check, test, and assemble. Linting happens during the check
// task and uses the spotless gradle plugin.
sh "./gradlew --no-daemon --no-parallel build testCodeCoverageReport"
}
}
stage('Upload PR to SonarQube') {
when {
changeRequest()
}
steps {
withSonarQubeEnv('sonarcloud.io') {
sh "./gradlew --no-daemon sonar -Duser.home=/tmp -Dsonar.host.url=${SONAR_HOST_URL} -Dsonar.token=${SONAR_AUTH_TOKEN} -Dsonar.pullrequest.key=${CHANGE_ID} -Dsonar.pullrequest.base=${CHANGE_TARGET} -Dsonar.pullrequest.branch=${BRANCH_NAME} -Dsonar.organization=rhsm -Dsonar.projectKey=rhsm-subscriptions"
}
}
}
stage('Upload Branch to SonarQube') {
when {
not {
changeRequest()
}
}
steps {
withSonarQubeEnv('sonarcloud.io') {
sh "./gradlew --no-daemon sonar -Duser.home=/tmp -Dsonar.host.url=${SONAR_HOST_URL} -Dsonar.token=${SONAR_AUTH_TOKEN} -Dsonar.branch.name=${BRANCH_NAME} -Dsonar.organization=rhsm -Dsonar.projectKey=rhsm-subscriptions"
}
}
}
stage('SonarQube Quality Gate') {
steps {
withSonarQubeEnv('sonarcloud.io') {
echo "SonarQube scan results will be visible at: ${SONAR_HOST_URL}/summary/new_code?id=rhsm-subscriptions${env.CHANGE_ID != null ? '&pullRequest=' + env.CHANGE_ID : ''}"
}
retry(4) {
script {
try {
timeout(time: 5, unit: 'MINUTES') {
waitForQualityGate abortPipeline: true
}
} catch (org.jenkinsci.plugins.workflow.steps.FlowInterruptedException e) {
// "rethrow" as something retry will actually retry, see https://issues.jenkins-ci.org/browse/JENKINS-51454
if (e.causes.find { it instanceof org.jenkinsci.plugins.workflow.steps.TimeoutStepExecution$ExceededTimeout } != null) {
error("Timeout waiting for SonarQube results")
}
}
}
}
}
}
}
post {
always {
containerLog "kubedock"
junit '**/build/test-results/test/*.xml'
}
}
}