Skip to content

Commit

Permalink
only run installation tests in prod
Browse files Browse the repository at this point in the history
upload videos and pdfs to nexus
use withCredentials block
publish html reports in jenkins
do not archive videos
  • Loading branch information
roicarrera committed Nov 14, 2024
1 parent 9f1bd9e commit 3e35b85
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 24 deletions.
81 changes: 57 additions & 24 deletions e2e-cypress/Jenkinsfile.template
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,6 @@ odsComponentPipeline(
]
) { context ->

// Note: Testing in the production environment is not recommended as it can lead to unintended consequences,
// including potential downtime, data corruption, or exposure of sensitive information.
// This block is designed to skip tests in the production environment to avoid these risks.
// If you choose to enable testing in production, do so at your own risk and take all necessary precautions.
if (context.environment == 'prod') {
currentBuild.result = 'SUCCESS'
echo 'Skipping the entire test build for production environment'
return
}

def targetDirectory = "${context.projectId}/${context.componentId}/${context.gitBranch.replaceAll('/', '-')}/${context.buildNumber}"

stageTest(context)
Expand All @@ -55,7 +45,26 @@ odsComponentPipeline(
]
)
}

if (fileExists('cypress/screenshots.zip')) {
odsComponentStageUploadToNexus(context,
[
distributionFile: 'cypress/screenshots.zip',
repository: 'leva-documentation',
repositoryType: 'raw',
targetDirectory: "${targetDirectory}"
]
)
}
if (fileExists('cypress/pdf.zip')) {
odsComponentStageUploadToNexus(context,
[
distributionFile: 'cypress/pdf.zip',
repository: 'leva-documentation',
repositoryType: 'raw',
targetDirectory: "${targetDirectory}"
]
)
}
}

def stageTest(def context) {
Expand All @@ -66,6 +75,7 @@ def stageTest(def context) {
: // remove this line once you have defined the config map and uncommented the next two lines, it's only here to make the example default case work
// dev: sh(returnStdout: true, script:"oc get configmaps cypress-config -o jsonpath='{.data.DEV_BASE_URL}'").trim(),
// test: sh(returnStdout: true, script:"oc get configmaps cypress-config -o jsonpath='{.data.TEST_BASE_URL}'").trim()
// prod: sh(returnStdout: true, script:"oc get configmaps cypress-config -o jsonpath='{.data.PROD_BASE_URL}'").trim()
]

def baseUrl = baseUrls.get(context.environment ?: 'dev', 'https://www.w3schools.com') // default to W3Schools for demo purposes, replace with your own default
Expand All @@ -75,42 +85,65 @@ def stageTest(def context) {
// test_username, test_password, etc.)
// cypressUser = sh(returnStdout: true, script:"oc get secret e2euser -o jsonpath='{.data.${context.environment}_username}' | base64 -d")
// cypressPassword = sh(returnStdout: true, script:"oc get secret e2euser -o jsonpath='{.data.${context.environment}_password}' | base64 -d")
// authenticatorOTPSecret = sh(returnStdout: true, script:"oc get secret azure -o jsonpath='{.data.OTP_SECRET}' | base64 -d")

withEnv(["TAGVERSION=${context.tagversion}",
"NEXUS_HOST=${context.nexusHost}",
"OPENSHIFT_PROJECT=${context.targetProject}",
"OPENSHIFT_APP_DOMAIN=${context.getOpenshiftApplicationDomain()}",
// "CYPRESS_USERNAME=${cypressUser}",
// "CYPRESS_PASSWORD=${cypressPassword}",
// "OTP_SECRET=${authenticatorOTPSecret}",
"COMMIT_INFO_SHA=${context.gitCommit}",
"BUILD_NUMBER=${context.buildNumber}",
"BASE_URL=${baseUrl}",
]) {
sh 'npm install'
def status = sh(script: 'npm run e2e', returnStatus: true)
sh 'npm run combine:reports'
junit(testResults:'build/test-results/*.xml', allowEmptyResults: true)
stash(name: "installation-test-reports-junit-xml-${context.componentId}-${context.buildNumber}", includes: 'build/test-results/installation-junit.xml', allowEmpty: true)
stash(name: "integration-test-reports-junit-xml-${context.componentId}-${context.buildNumber}", includes: 'build/test-results/integration-junit.xml', allowEmpty: true)
stash(name: "acceptance-test-reports-junit-xml-${context.componentId}-${context.buildNumber}", includes: 'build/test-results/acceptance-junit.xml', allowEmpty: true)
withCredentials([
// string(credentialsId: cypressUser, variable: 'CYPRESS_USERNAME'),
// string(credentialsId: cypressPassword, variable: 'CYPRESS_PASSWORD'),
// string(credentialsId: authenticatorOTPSecret, variable: 'OTP_SECRET')
]) {
sh 'npm install'

// Note: Testing in the production environment is not recommended as it can lead to unintended consequences,
// including potential downtime, data corruption, or exposure of sensitive information.
// This block is designed to skip acceptance and integration tests in the production environment to avoid these risks.
// If you choose to enable these tests in production, do so at your own risk and take all necessary precautions.
def status
if (context.environment == 'prod') {
status = sh(script: 'npm run e2e:prod', returnStatus: true)
sh 'npm run junit-installation-report'
junit(testResults:'build/test-results/*.xml', allowEmptyResults: true)
stash(name: "installation-test-reports-junit-xml-${context.componentId}-${context.buildNumber}", includes: 'build/test-results/installation-junit.xml', allowEmpty: true)
} else {
status = sh(script: 'npm run e2e', returnStatus: true)
sh 'npm run combine:reports'
junit(testResults:'build/test-results/*.xml', allowEmptyResults: true)
stash(name: "installation-test-reports-junit-xml-${context.componentId}-${context.buildNumber}", includes: 'build/test-results/installation-junit.xml', allowEmpty: true)
stash(name: "integration-test-reports-junit-xml-${context.componentId}-${context.buildNumber}", includes: 'build/test-results/integration-junit.xml', allowEmpty: true)
stash(name: "acceptance-test-reports-junit-xml-${context.componentId}-${context.buildNumber}", includes: 'build/test-results/acceptance-junit.xml', allowEmpty: true)
}
}

publishHTML (target : [
allowMissing: false,
alwaysLinkToLastBuild: true,
keepAll: true,
reportDir: 'build/test-results',
reportFiles: '**/*.html'
])

sh 'npm run generate:pdf'
zip zipFile: 'cypress/pdf.zip', archive: false, dir: 'build/test-results/mochawesome/pdf'
archiveArtifacts artifacts: 'cypress/pdf.zip', fingerprint: true, daysToKeep: 2, numToKeep: 3

if (fileExists('cypress/videos')) {
zip zipFile: 'cypress/videos.zip', archive: false, dir: 'cypress/videos'
stash(name: "acceptance-test-videos-${context.componentId}-${context.buildNumber}", includes: 'cypress/videos.zip', allowEmpty: true)
archiveArtifacts artifacts: 'cypress/videos.zip', fingerprint: true, daysToKeep: 2, numToKeep: 3
}

if (fileExists('build/test-results/screenshots')) {
zip zipFile: 'cypress/screenshots.zip', archive: false, dir: 'build/test-results/screenshots'
stash(name: "acceptance-test-screenshots-${context.componentId}-${context.buildNumber}", includes: 'cypress/screenshots.zip', allowEmpty: true)
archiveArtifacts artifacts: 'cypress/screenshots.zip', fingerprint: true, daysToKeep: 2, numToKeep: 3
}

return status
}
}
Expand Down
2 changes: 2 additions & 0 deletions e2e-cypress/files/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@
"junit-acceptance-report": "jrm build/test-results/acceptance-junit.xml 'build/test-results/acceptance-*.xml'",
"delete-junit-results": "rimraf build/test-results",
"e2e": "npm-run-all delete-junit-results cypress:run-installation cypress:run-integration cypress:run-acceptance",
"e2e:prod": "npm-run-all delete-junit-results cypress:run-installation",
"combine:reports": "npm-run-all junit-installation-report junit-integration-report junit-acceptance-report",
"e2e:jenkins:record": "npm run delete-junit-results && npm run cypress:run-installation -- --record && npm run cypress:run-integration -- --record && npm run cypress:run-acceptance -- --record",
"e2e:jenkins:report:prod": "npm run delete-junit-results && npm run cypress:run-installation -- --record",
"generate:pdf": "ts-node ./pdf-generator.ts"
},
"private": true,
Expand Down

0 comments on commit 3e35b85

Please sign in to comment.