Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature ETP-893: Update HTML Report Publishing in Pipelines #562

Merged
merged 3 commits into from
Dec 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
131 changes: 83 additions & 48 deletions pipelines/unittests/Jenkinsfile
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

GPT Review for Jenkinsfile

Review

  • Estimated effort to review [1-5]:
    3, because the changes involve multiple sections of the Jenkinsfile, adding conditional checks and modifying the test stages. The complexity is moderate, requiring a careful review of the logic and structure.
  • Score: 85

Code feedback

  • File:
    pipelines/unittests/Jenkinsfile
  • Language:
    groovy
  • Suggestion:
    Consider using a constant or a variable for the report directory path to avoid repetition and potential errors if the path needs to be updated in the future. This will improve maintainability and reduce the risk of inconsistencies. [medium]
  • Label:
    maintainability
  • Existing code:
if (fileExists("build/reports/tests/test/")) {
  publishHTML([
    allowMissing: true,
    alwaysLinkToLastBuild: false,
    keepAll: true,
    reportDir: 'build/reports/tests/test',
    reportFiles: '*.html',
    reportName: 'WEBSERVICES TESTS REPORT',
    reportTitles: ''
  ])
  sh "rm -rf build/reports/tests/test"
} else {
  echo "Report directory of Webservices tests does not exist. Skipping HTML report publishing."
}
  • Improved code:
def reportDirPath = "build/reports/tests/test"
if (fileExists(reportDirPath)) {
  publishHTML([
    allowMissing: true,
    alwaysLinkToLastBuild: false,
    keepAll: true,
    reportDir: reportDirPath,
    reportFiles: '*.html',
    reportName: 'WEBSERVICES TESTS REPORT',
    reportTitles: ''
  ])
  sh "rm -rf ${reportDirPath}"
} else {
  echo "Report directory of Webservices tests does not exist. Skipping HTML report publishing."
}
  • File:
    pipelines/unittests/Jenkinsfile
  • Language:
    groovy
  • Suggestion:
    Ensure that the sh "./gradlew --stop" command is necessary in all places it is used. If it is not required after every test suite, consider removing it to optimize the build process. [medium]
  • Label:
    performance
  • Existing code:
sh "./gradlew --stop"
  • Improved code:
// Evaluate if this command is necessary in all instances
sh "./gradlew --stop"

Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ spec:
}
}
// __________________________________________________________________________________________
// ------------------------------ WEB SERVICE TEST ------------------------------------------
// ------------------------------ WEB SERVICES TESTS ----------------------------------------
stage ('Web Service Test Suite') { // MARK: Web Service Test Suite
when {
expression {
Expand All @@ -261,21 +261,26 @@ spec:
echo "--------------- WebserviceTestSuite Failed ---------------"
echo 'Exception occurred: ' + e.toString()
currentBuild.result = UNSTABLE
unstable('WebserviceTestSuite Failed')
unstable('WebservicesTestSuite Failed')
env.STATUSTEST = "0"
} finally {
publishHTML([
allowMissing: false,
alwaysLinkToLastBuild: false,
keepAll: true,
reportDir: 'build/reports/tests/test',
reportFiles: '*.html',
reportName: 'WEBSERVICES TESTS REPORT',
reportTitles: ''
])
if (fileExists("build/reports/tests/test/")) {
publishHTML([
allowMissing: true,
alwaysLinkToLastBuild: false,
keepAll: true,
reportDir: 'build/reports/tests/test',
reportFiles: '*.html',
reportName: 'WEBSERVICES TESTS REPORT',
reportTitles: ''
])
sh "rm -rf build/reports/tests/test"
} else {
echo "Report directory of Webservices tests does not exist. Skipping HTML report publishing."
}
sh "${WORKSPACE}/${TOMCAT_FOLDER}/bin/catalina.sh stop"
sh "./gradlew --stop"
}
sh "${WORKSPACE}/${TOMCAT_FOLDER}/bin/catalina.sh stop"
sh "./gradlew --stop"
}
}
}
Expand All @@ -290,7 +295,6 @@ spec:
}
}
steps {
sh "./pipelines/unittests/build-update.sh ${REPO_NAME} ${COMMIT_INPROGRESS_STATUS} \"Running Test Suites\" ${ACCESS_TOKEN} ${GIT_COMMIT} ${BUILD_URL} \"${CONTEXT_BUILD}\""
container('compiler') {
script {
dir(REPO_NAME) {
Expand All @@ -307,23 +311,29 @@ spec:
unstable('CoreTestSuite Failed')
env.STATUSTEST = "0"
} finally {
publishHTML([
allowMissing: false,
alwaysLinkToLastBuild: false,
keepAll: true,
reportDir: 'build/reports/tests/test',
reportFiles: '*.html',
reportName: 'com.smf.* TESTS REPORT',
reportTitles: ''
])
if (fileExists("build/reports/tests/test/")) {
publishHTML([
allowMissing: false,
alwaysLinkToLastBuild: false,
keepAll: true,
reportDir: 'build/reports/tests/test',
reportFiles: '*.html',
reportName: 'com.smf.* TESTS REPORT',
reportTitles: ''
])
sh "rm -rf build/reports/tests/test"
} else {
echo "Report directory of com.smf.* tests does not exist. Skipping HTML report publishing."
}

}
}
}
}
}
}
// __________________________________________________________________________________________
// ------------------------------- STANDALONE TEST ------------------------------------------
// ------------------------------- STANDALONE TESTS -----------------------------------------
stage ('Standalone Test Suite') { // MARK: Standalone Test Suite
when {
expression {
Expand All @@ -347,24 +357,29 @@ spec:
unstable('StandaloneTestSuite Failed')
env.STATUSTEST = "0"
} finally {
publishHTML([
allowMissing: false,
alwaysLinkToLastBuild: false,
keepAll: true,
reportDir: 'build/reports/tests/test',
reportFiles: '*.html',
reportName: 'STANDALONE TESTS REPORT',
reportTitles: ''
])
if (fileExists("build/reports/tests/test/")) {
publishHTML([
allowMissing: true,
alwaysLinkToLastBuild: false,
keepAll: true,
reportDir: 'build/reports/tests/test',
reportFiles: '*.html',
reportName: 'STANDALONE TESTS REPORT',
reportTitles: ''
])
sh "rm -rf build/reports/tests/test"
} else {
echo "Report directory of Standalone tests does not exist. Skipping HTML report publishing."
}
}
}
}
}
}
}
// __________________________________________________________________________________________
// ----------------------------------- SPOCK TEST -------------------------------------------
stage ('Spock Test') { // MARK: Spock Test
// ----------------------------------- com.etendoerp.* TESTS --------------------------------
stage ('com.etendoerp.* Tests') { // MARK: com.etendoerp.* Test
when {
expression {
env.STATUSBUILD == "1"
Expand All @@ -375,28 +390,48 @@ spec:
script {
dir(REPO_NAME) {
try {
echo "--------------- Running Spock Test ---------------"
echo "--------------- Running com.etendoerp.* Tests ---------------"
sh "./gradlew test --tests \"com.etendoerp.*\" --info"
sh "mv build/jacoco/test.exec build/jacoco/test3.exec"
sh "./gradlew --stop"
echo "--------------- Spock Test Successful ---------------"
echo "--------------- com.etendoerp.* Tests Successful ---------------"
currentBuild.result = SUCCESS
} catch (Exception e) {
echo "--------------- Spock Test Failed ---------------"
echo "--------------- com.etendoerp.* Tests Failed ---------------"
echo 'Exception occurred: ' + e.toString()
currentBuild.result = UNSTABLE
unstable('Spock Test failed!')
unstable('com.etendoerp.* Tests failed!')
env.STATUSTEST = "0"
} finally {
publishHTML([
allowMissing: false,
alwaysLinkToLastBuild: false,
keepAll: true,
reportDir: 'build/spock-reports/',
reportFiles: '*.html',
reportName: 'SPOCK TESTS REPORT',
reportTitles: ''
])
if (fileExists('build/spock-reports/')) {
publishHTML([
allowMissing: true,
alwaysLinkToLastBuild: false,
keepAll: true,
reportDir: 'build/spock-reports/',
reportFiles: '*.html',
reportName: 'com.etendoerp.* SPOCK TESTS REPORT',
reportTitles: ''
])
sh "rm -rf build/spock-reports"
} else {
echo "Spock report directory of com.etendoerp.* tests does not exist. Skipping HTML report publishing."
}

if (fileExists('build/reports/tests/test/')) {
publishHTML([
allowMissing: true,
alwaysLinkToLastBuild: false,
keepAll: true,
reportDir: 'build/reports/tests/test',
reportFiles: '*.html',
reportName: 'com.etendoerp.* TESTS REPORT',
reportTitles: ''
])
sh "rm -rf build/reports/tests/test"
} else {
echo "Report directory of com.etendoerp.* tests does not exist. Skipping HTML report publishing."
}
}
}
}
Expand Down
Loading
Loading