-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy pathJenkinsfile
154 lines (150 loc) · 5.08 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
pipeline {
options {
disableConcurrentBuilds()
}
agent any
tools {
maven 'maven-3.6.0'
jdk 'jdk11'
}
triggers {
// timer trigger for "nightly build" on main branch
cron( env.BRANCH_NAME.equals('main') ? 'H H(0-3) * * 1-5' : '')
}
environment {
// variables for SystemTest stages (integration tests)
STAGING_DIR = "/scratch/artifacts/imagetool"
DB_IMAGE = "phx.ocir.io/weblogick8s/database/enterprise:12.2.0.1-slim"
}
stages {
stage ('Environment') {
steps {
sh '''
echo "PATH = ${PATH}"
echo "M2_HOME = ${M2_HOME}"
mvn --version
'''
}
}
stage ('Build') {
steps {
sh 'mvn -B -DskipTests -DskipITs clean install'
}
}
stage ('Unit Tests') {
when {
not { changelog '\\[skip-ci\\].*' }
}
steps {
sh 'mvn test'
}
post {
always {
junit 'imagetool/target/surefire-reports/*.xml'
}
}
}
stage ('Sonar Analysis') {
when {
anyOf {
changeRequest()
branch "main"
}
}
tools {
maven 'maven-3.6.0'
jdk 'jdk11'
}
steps {
withSonarQubeEnv('SonarCloud') {
withCredentials([string(credentialsId: 'encj_github_token', variable: 'GITHUB_TOKEN')]) {
runSonarScanner()
}
}
}
}
stage ('SystemTest Gate') {
when {
allOf {
changeRequest target: 'main'
not { changelog '\\[skip-ci\\].*' }
not { changelog '\\[full-mats\\].*' }
}
}
steps {
withCredentials([[$class: 'UsernamePasswordMultiBinding', credentialsId: 'otn-cred', passwordVariable: 'ORACLE_SUPPORT_PASSWORD', usernameVariable: 'ORACLE_SUPPORT_USERNAME']]) {
sh '''
cd tests
mvn clean verify -Dtest.staging.dir=${STAGING_DIR} -Dtest.groups=gate -DskipITs=false
'''
}
}
post {
always {
junit 'tests/target/failsafe-reports/*.xml'
}
}
}
stage ('SystemTest Full') {
when {
anyOf {
triggeredBy 'TimerTrigger'
tag 'release-*'
changelog '\\[full-mats\\].*'
}
}
steps {
script {
docker.image("${env.DB_IMAGE}").pull()
}
withCredentials([[$class: 'UsernamePasswordMultiBinding', credentialsId: 'otn-cred', passwordVariable: 'ORACLE_SUPPORT_PASSWORD', usernameVariable: 'ORACLE_SUPPORT_USERNAME']]) {
sh '''
cd tests
mvn clean verify -Dtest.staging.dir=${STAGING_DIR} -Dtest.groups=gate,nightly -DskipITs=false
'''
}
}
post {
always {
junit 'tests/target/failsafe-reports/*.xml'
}
failure {
mail to: "${env.WIT_BUILD_NOTIFICATION_EMAIL_TO}", from: 'noreply@oracle.com',
subject: "WebLogic Image Tool: ${env.JOB_NAME} - Failed",
body: "Job Failed - \"${env.JOB_NAME}\" build: ${env.BUILD_NUMBER}\n\nView the log at:\n ${env.BUILD_URL}\n"
}
}
}
stage ('Save Nightly Installer'){
when {
allOf {
triggeredBy 'TimerTrigger'
branch "main"
}
}
steps {
sh '''
oci os object put --namespace=weblogick8s --bucket-name=wko-system-test-files --config-file=/dev/null --auth=instance_principal --force --file=installer/target/imagetool.zip --name=imagetool-main.zip
'''
}
}
}
}
void runSonarScanner() {
def changeUrl = env.GIT_URL.split("/")
def org = changeUrl[3]
def repo = changeUrl[4].substring(0, changeUrl[4].length() - 4)
if (env.CHANGE_ID != null) {
sh "mvn -B sonar:sonar \
-Dsonar.projectKey=${org}_${repo} \
-Dsonar.pullrequest.provider=GitHub \
-Dsonar.pullrequest.github.repository=${org}/${repo} \
-Dsonar.pullrequest.key=${env.CHANGE_ID} \
-Dsonar.pullrequest.branch=${env.CHANGE_BRANCH} \
-Dsonar.pullrequest.base=${env.CHANGE_TARGET}"
} else {
sh "mvn -B sonar:sonar \
-Dsonar.projectKey=${org}_${repo} \
-Dsonar.branch.name=${env.BRANCH_NAME}"
}
}