diff --git a/Jenkinsfile-SmokeTest b/Jenkinsfile-SmokeTest index b5677c09..3b85065a 100644 --- a/Jenkinsfile-SmokeTest +++ b/Jenkinsfile-SmokeTest @@ -16,40 +16,20 @@ properties([ // Generates a custom route file that contains the next version of Angular to test against def generateNPMVersionRouteFile(Map args = new LinkedHashMap()) { - // @angular/core's version is the one baked into the angular app - def nextVersion = sh(script: "npm view @angular/core@${args.npm_tag} version", returnStdout: true).trim() - - echo "Target framework version: ${nextVersion}" - - def routeFileContent = readJSON text: """ - [{ - "request": { - "method": "get", - "path": "/custom/integration/info" - }, - "response": { - "status": 200, - "json": { - "version": "${nextVersion}" - } - } - }] - """ - writeJSON file: "${args.filePath}", json: routeFileContent + writeJSON file: "${args.filePath}", json: args.content } // Updates the Angular dependencies to the version specified by the npm tag def updateDependenciesWithTag(Map args = new LinkedHashMap()) { - String npm_tag = args.npm_tag - sh "yarn add @angular/core@${npm_tag} @angular/animations@${npm_tag} @angular/common@${npm_tag} @angular/compiler@${npm_tag} @angular/core@${npm_tag} @angular/forms@${npm_tag} @angular/platform-browser@${npm_tag} @angular-devkit/build-angular@${npm_tag} @angular/cli@${npm_tag} @angular/compiler-cli@${npm_tag}" + sh "yarn add @angular/core@${args.npmTag} @angular/animations@${args.npmTag} @angular/common@${args.npmTag} @angular/compiler@${args.npmTag} @angular/core@${args.npmTag} @angular/forms@${args.npmTag} @angular/platform-browser@${args.npmTag} @angular-devkit/build-angular@${args.npmTag} @angular/cli@${args.npmTag} @angular/compiler-cli@${args.npmTag}" } def runSmokeTests(Map args = new LinkedHashMap()) { def platforms = args.platforms ?: [ [ browser: "chrome", provider: "lambdatest" ] ] - String customRouteFilePath = "${WORKSPACE}/version.json" - String additionalArgs = "--chunk 20 --totalTimeout 1800000 --singleTimeout 90000 --retries 3 --customRoutes ${customRouteFilePath}" + String routeFilePath = "${WORKSPACE}/customRoutes.json" + String additionalArgs = "--chunk 20 --totalTimeout 1800000 --singleTimeout 90000 --retries 3 --customRoutes ${routeFilePath}" def processes = [:] @@ -77,8 +57,8 @@ def runSmokeTests(Map args = new LinkedHashMap()) { customArgs = customArgs + " --platformName \"${platform.os}\"" } - generateNPMVersionRouteFile(npm_tag: args.npm_tag, filePath: customRouteFilePath) - updateDependenciesWithTag(npm_tag: args.npm_tag) + generateNPMVersionRouteFile(content: args.routeContent, filePath: routeFilePath) + updateDependenciesWithTag(npmTag: args.npmTag) bedrockTests( name: name, browser: platform.browser, @@ -95,8 +75,8 @@ def runSmokeTests(Map args = new LinkedHashMap()) { def name = "headless-${platform.browser}${suffix}" processes[name] = { stage("${name}") { - generateNPMVersionRouteFile(npm_tag: args.npm_tag, filePath: customRouteFilePath) - updateDependenciesWithTag(npm_tag: args.npm_tag) + generateNPMVersionRouteFile(content: args.routeContent, filePath: routeFilePath) + updateDependenciesWithTag(npmTag: args.npmTag) bedrockTests( name: name, browser: platform.browser, @@ -114,6 +94,14 @@ def runSmokeTests(Map args = new LinkedHashMap()) { parallel processes } +def notify(Map slackArgs) { + // In shared libraries, the `call` method is not in the pipeline CPS context. We need to call the `steps` object to safely call jenkins steps + steps.retry(3) { + return steps.slackSend([ username: 'TinyMCE Integration Smoke Test', failOnError: true ] + slackArgs) + } +} + + timestamps { tinyPods.node() { stage('deps') { @@ -125,7 +113,43 @@ timestamps { } stage('tests') { - runSmokeTests(npm_tag: params.NPM_TAG ?: 'latest') + String npmTag = params.NPM_TAG ?: 'latest' + // @angular/core's version is the one baked into the angular app + String nextVersion = sh(script: "npm view @angular/core@${npmTag} version", returnStdout: true).trim() + echo "The upcoming Angular version: ${nextVersion}" + + def customRouteContent = readJSON text: """ + [{ + "request": { + "method": "get", + "path": "/custom/integration/info" + }, + "response": { + "status": 200, + "json": { + "version": "${nextVersion}" + } + } + }] + """ + + try { + runSmokeTests(npmTag: npmTag, routeContent: customRouteContent) + } catch (Exception e) { + echo "Exception was caught: ${e}" + currentBuild.result = 'FAILURE' + } finally { + if (currentBuild.resultIsWorseOrEqualTo('UNSTABLE')) { + def color = ['UNSTABLE': 'warning', 'FAILURE': 'danger'] + def message = currentBuild.result == 'UNSTABLE' ? "Tests failed" : 'An unexpected error occurred while running tests' + + notify( + channel: '#tiny-integrations-dev', + color: color.get(currentBuild.result, '#808080'), + message: "${env.JOB_NAME} against ${nextVersion} failed: ${message} (<${env.BUILD_URL}|Open>)" + ) + } + } } } }