Skip to content

Commit b382505

Browse files
committed
Merge branch 'orahub-environment' into 'main'
Changed build to accommodate multiple GIT repositories like Orahub See merge request weblogic-cloud/weblogic-image-tool!445
2 parents 8926c9e + 57e8fd0 commit b382505

File tree

4 files changed

+108
-76
lines changed

4 files changed

+108
-76
lines changed

Jenkinsfile

Lines changed: 100 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ pipeline {
44
}
55
agent any
66
tools {
7-
maven 'maven-3.6.0'
7+
maven 'maven-3.8.7'
88
jdk 'jdk11'
99
}
1010

@@ -15,10 +15,10 @@ pipeline {
1515

1616
environment {
1717
// variables for SystemTest stages (integration tests)
18-
STAGING_DIR = "/scratch/artifacts/imagetool"
19-
DB_IMAGE = "phx.ocir.io/weblogick8s/database/enterprise:12.2.0.1-slim"
20-
GITHUB_API_TOKEN = credentials('encj_github_token')
21-
GH_TOOL = tool name: 'github-cli', type: 'com.cloudbees.jenkins.plugins.customtools.CustomTool'
18+
STAGING_DIR = "${WORKSPACE}/wit-system-test-files"
19+
DB_IMAGE = "${WKT_OCIR_HOST}/${WKT_TENANCY}/database/enterprise:12.2.0.1-slim"
20+
// GITHUB_API_TOKEN = credentials('encj_github_token')
21+
// GH_TOOL = tool name: 'github-cli', type: 'com.cloudbees.jenkins.plugins.customtools.CustomTool'
2222
}
2323

2424
stages {
@@ -33,39 +33,59 @@ pipeline {
3333
}
3434
stage ('Build') {
3535
steps {
36-
sh 'mvn -B -DskipTests -DskipITs clean install'
36+
withMaven(globalMavenSettingsConfig: 'wkt-maven-settings-xml', publisherStrategy: 'EXPLICIT') {
37+
sh 'mvn -B -DskipTests -DskipITs clean install'
38+
}
3739
}
3840
}
3941
stage ('Unit Tests') {
4042
when {
4143
not { changelog '\\[skip-ci\\].*' }
4244
}
4345
steps {
44-
sh 'mvn test'
46+
withMaven(globalMavenSettingsConfig: 'wkt-maven-settings-xml', publisherStrategy: 'EXPLICIT') {
47+
sh 'mvn -B test'
48+
}
4549
}
4650
post {
4751
always {
4852
junit 'imagetool/target/surefire-reports/*.xml'
4953
}
5054
}
5155
}
52-
stage ('Sonar Analysis') {
56+
// stage ('Sonar Analysis') {
57+
// when {
58+
// anyOf {
59+
// changeRequest()
60+
// branch "main"
61+
// }
62+
// }
63+
// tools {
64+
// maven 'maven-3.8.7'
65+
// jdk 'jdk11'
66+
// }
67+
// steps {
68+
// withSonarQubeEnv('SonarCloud') {
69+
// withCredentials([string(credentialsId: 'encj_github_token', variable: 'GITHUB_TOKEN')]) {
70+
// runSonarScanner()
71+
// }
72+
// }
73+
// }
74+
// }
75+
stage ('Download System Test Files') {
5376
when {
5477
anyOf {
55-
changeRequest()
56-
branch "main"
78+
changeRequest target: 'main'
79+
triggeredBy 'TimerTrigger'
80+
changelog '\\[full-mats\\].*'
5781
}
5882
}
59-
tools {
60-
maven 'maven-3.6.0'
61-
jdk 'jdk11'
62-
}
6383
steps {
64-
withSonarQubeEnv('SonarCloud') {
65-
withCredentials([string(credentialsId: 'encj_github_token', variable: 'GITHUB_TOKEN')]) {
66-
runSonarScanner()
67-
}
68-
}
84+
sh '''
85+
rm -rf ${STAGING_DIR}
86+
mkdir ${STAGING_DIR}
87+
oci os object bulk-download --namespace devweblogic --bucket-name wit-system-test-files --config-file=/dev/null --auth=instance_principal --download-dir ${STAGING_DIR}
88+
'''
6989
}
7090
}
7191
stage ('SystemTest Gate') {
@@ -77,17 +97,22 @@ pipeline {
7797
}
7898
}
7999
steps {
80-
withCredentials([[$class: 'UsernamePasswordMultiBinding', credentialsId: 'otn-cred', passwordVariable: 'ORACLE_SUPPORT_PASSWORD', usernameVariable: 'ORACLE_SUPPORT_USERNAME']]) {
81-
sh '''
82-
cd tests
83-
mvn clean verify -Dtest.staging.dir=${STAGING_DIR} -Dtest.groups=gate -DskipITs=false
84-
'''
100+
withCredentials([[$class: 'UsernamePasswordMultiBinding', credentialsId: 'wkt-otn-credential', passwordVariable: 'ORACLE_SUPPORT_PASSWORD', usernameVariable: 'ORACLE_SUPPORT_USERNAME']]) {
101+
withMaven(globalMavenSettingsConfig: 'wkt-maven-settings-xml', publisherStrategy: 'EXPLICIT') {
102+
sh '''
103+
cd tests
104+
mvn -B clean verify -Dtest.staging.dir=${STAGING_DIR} -Dtest.groups=gate -DskipITs=false
105+
'''
106+
}
85107
}
86108
}
87109
post {
88110
always {
89111
junit 'tests/target/failsafe-reports/*.xml'
90112
}
113+
failure {
114+
archiveArtifacts artifacts: 'tests/target/logs/*.*', onlyIfSuccessful: 'false'
115+
}
91116
}
92117
}
93118
stage ('SystemTest Full') {
@@ -101,21 +126,25 @@ pipeline {
101126
script {
102127
docker.image("${env.DB_IMAGE}").pull()
103128
}
104-
withCredentials([[$class: 'UsernamePasswordMultiBinding', credentialsId: 'otn-cred', passwordVariable: 'ORACLE_SUPPORT_PASSWORD', usernameVariable: 'ORACLE_SUPPORT_USERNAME']]) {
105-
sh '''
106-
cd tests
107-
mvn clean verify -Dtest.staging.dir=${STAGING_DIR} -Dtest.groups=gate,nightly -DskipITs=false
108-
'''
129+
withCredentials([[$class: 'UsernamePasswordMultiBinding', credentialsId: 'wkt-otn-credential', passwordVariable: 'ORACLE_SUPPORT_PASSWORD', usernameVariable: 'ORACLE_SUPPORT_USERNAME']]) {
130+
withMaven(globalMavenSettingsConfig: 'wkt-maven-settings-xml', publisherStrategy: 'EXPLICIT') {
131+
sh '''
132+
cd tests
133+
mvn -B clean verify -Dtest.staging.dir=${STAGING_DIR} -Dtest.groups=gate,nightly -DskipITs=false
134+
'''
135+
}
109136
}
110137
}
111138
post {
112139
always {
113140
junit 'tests/target/failsafe-reports/*.xml'
114141
}
115142
failure {
116-
mail to: "${env.WIT_BUILD_NOTIFICATION_EMAIL_TO}", from: '[email protected]',
117-
subject: "WebLogic Image Tool: ${env.JOB_NAME} - Failed",
118-
body: "Job Failed - \"${env.JOB_NAME}\" build: ${env.BUILD_NUMBER}\n\nView the log at:\n ${env.BUILD_URL}\n"
143+
// save logs for debugging test failures
144+
archiveArtifacts artifacts: 'tests/target/logs/*.*', onlyIfSuccessful: 'false'
145+
// notify staff when nightly builds fail
146+
slackSend channel: '#wkt-build-failure-notifications', botUser: false, color: 'danger',
147+
message: "Build failed. WebLogic Image Tool: <${env.BUILD_URL}|${env.JOB_NAME}:${env.BUILD_NUMBER}>"
119148
}
120149
}
121150
}
@@ -128,48 +157,48 @@ pipeline {
128157
}
129158
steps {
130159
sh '''
131-
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
160+
oci os object put --namespace=${WKT_TENANCY} --bucket-name=wko-system-test-files --config-file=/dev/null --auth=instance_principal --force --file=installer/target/imagetool.zip --name=imagetool-main.zip
132161
'''
133162
}
134163
}
135-
stage ('Create Draft Release') {
136-
when {
137-
tag 'release-*'
138-
}
139-
steps {
140-
script {
141-
env.TAG_VERSION_NUMBER = env.TAG_NAME.replaceAll('release-','').trim()
142-
}
143-
144-
sh """
145-
echo '${env.GITHUB_API_TOKEN}' | ${GH_TOOL}/bin/gh auth login --with-token
146-
${GH_TOOL}/bin/gh release create ${TAG_NAME} \
147-
--draft \
148-
--generate-notes \
149-
--title 'WebLogic Image Tool ${TAG_VERSION_NUMBER}' \
150-
--repo https://github.com/oracle/weblogic-image-tool \
151-
installer/target/imagetool.zip
152-
"""
153-
}
154-
}
164+
// stage ('Create Draft Release') {
165+
// when {
166+
// tag 'release-*'
167+
// }
168+
// steps {
169+
// script {
170+
// env.TAG_VERSION_NUMBER = env.TAG_NAME.replaceAll('release-','').trim()
171+
// }
172+
//
173+
// sh """
174+
// echo '${env.GITHUB_API_TOKEN}' | ${GH_TOOL}/bin/gh auth login --with-token
175+
// ${GH_TOOL}/bin/gh release create ${TAG_NAME} \
176+
// --draft \
177+
// --generate-notes \
178+
// --title 'WebLogic Image Tool ${TAG_VERSION_NUMBER}' \
179+
// --repo https://github.com/oracle/weblogic-image-tool \
180+
// installer/target/imagetool.zip
181+
// """
182+
// }
183+
// }
155184
}
156185
}
157186

158-
void runSonarScanner() {
159-
def changeUrl = env.GIT_URL.split("/")
160-
def org = changeUrl[3]
161-
def repo = changeUrl[4].substring(0, changeUrl[4].length() - 4)
162-
if (env.CHANGE_ID != null) {
163-
sh "mvn -B sonar:sonar \
164-
-Dsonar.projectKey=${org}_${repo} \
165-
-Dsonar.pullrequest.provider=GitHub \
166-
-Dsonar.pullrequest.github.repository=${org}/${repo} \
167-
-Dsonar.pullrequest.key=${env.CHANGE_ID} \
168-
-Dsonar.pullrequest.branch=${env.CHANGE_BRANCH} \
169-
-Dsonar.pullrequest.base=${env.CHANGE_TARGET}"
170-
} else {
171-
sh "mvn -B sonar:sonar \
172-
-Dsonar.projectKey=${org}_${repo} \
173-
-Dsonar.branch.name=${env.BRANCH_NAME}"
174-
}
175-
}
187+
//void runSonarScanner() {
188+
// def changeUrl = env.GIT_URL.split("/")
189+
// def org = changeUrl[3]
190+
// def repo = changeUrl[4].substring(0, changeUrl[4].length() - 4)
191+
// if (env.CHANGE_ID != null) {
192+
// sh "mvn -B sonar:sonar \
193+
// -Dsonar.projectKey=${org}_${repo} \
194+
// -Dsonar.pullrequest.provider=GitHub \
195+
// -Dsonar.pullrequest.github.repository=${org}/${repo} \
196+
// -Dsonar.pullrequest.key=${env.CHANGE_ID} \
197+
// -Dsonar.pullrequest.branch=${env.CHANGE_BRANCH} \
198+
// -Dsonar.pullrequest.base=${env.CHANGE_TARGET}"
199+
// } else {
200+
// sh "mvn -B sonar:sonar \
201+
// -Dsonar.projectKey=${org}_${repo} \
202+
// -Dsonar.branch.name=${env.BRANCH_NAME}"
203+
// }
204+
//}

pom.xml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,10 @@
113113
<variableName>ORACLE_SUPPORT_PASSWORD</variableName>
114114
<message>For integration tests, you must set the environment variable ORACLE_SUPPORT_PASSWORD to match the ORACLE_SUPPORT_USERNAME credential.</message>
115115
</requireEnvironmentVariable>
116+
<requireEnvironmentVariable>
117+
<variableName>DB_IMAGE</variableName>
118+
<message>For integration tests, you must set the environment variable DB_IMAGE to a database container image.</message>
119+
</requireEnvironmentVariable>
116120
<requireProperty>
117121
<property>test.staging.dir</property>
118122
<message>For integration tests, you must define the test.staging.dir System property to point to the directory where the installers are staged. Or, set STAGING_DIR environment variable.</message>
@@ -221,7 +225,7 @@
221225
<consoleOutput>true</consoleOutput>
222226
<configLocation>weblogic-image-tool/checkstyle/customized_google_checks.xml</configLocation>
223227
<suppressionsLocation>weblogic-image-tool/checkstyle/suppressions.xml</suppressionsLocation>
224-
<encoding>UTF-8</encoding>
228+
<inputEncoding>UTF-8</inputEncoding>
225229
<failOnViolation>true</failOnViolation>
226230
<violationSeverity>warning</violationSeverity>
227231
<includeTestSourceDirectory>true</includeTestSourceDirectory>

tests/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@
9191
<WLSIMG_BLDDIR>${project.build.directory}/blddir</WLSIMG_BLDDIR>
9292
<WLSIMG_CACHEDIR>${project.build.directory}/cachedir</WLSIMG_CACHEDIR>
9393
<STAGING_DIR>${test.staging.dir}</STAGING_DIR>
94-
<DB_IMAGE>phx.ocir.io/weblogick8s/database/enterprise:12.2.0.1-slim</DB_IMAGE>
94+
<DB_IMAGE>${env.DB_IMAGE}</DB_IMAGE>
9595
</systemPropertyVariables>
9696
</configuration>
9797
<executions>

tests/src/test/java/com/oracle/weblogic/imagetool/tests/ITImagetool.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66
import java.io.BufferedWriter;
77
import java.io.File;
8-
import java.io.FileOutputStream;
98
import java.io.IOException;
109
import java.io.OutputStreamWriter;
1110
import java.io.PrintWriter;
@@ -117,7 +116,7 @@ private static void validateEnvironmentSettings() {
117116
// get the build tag from Jenkins build environment variable BUILD_TAG
118117
build_tag = System.getenv("BUILD_TAG");
119118
if (build_tag != null) {
120-
build_tag = build_tag.toLowerCase();
119+
build_tag = build_tag.toLowerCase().replaceAll("\\s+", "-");
121120
} else {
122121
build_tag = "imagetool-itest";
123122
}
@@ -251,7 +250,7 @@ private static PrintWriter getTestMethodWriter(TestInfo testInfo) throws IOExcep
251250
Files.createDirectories(outputPath.getParent());
252251
logger.info("Test log: {0}", outputPath.toString());
253252
return new PrintWriter(
254-
new BufferedWriter(new OutputStreamWriter(new FileOutputStream(outputPath.toString()))), true);
253+
new BufferedWriter(new OutputStreamWriter(Files.newOutputStream(outputPath))), true);
255254
} else {
256255
throw new IllegalArgumentException("Method is not present in this context, and this method cannot be used");
257256
}

0 commit comments

Comments
 (0)