From f21d74ff755329dd933cabcd512eac4dd183dd5f Mon Sep 17 00:00:00 2001 From: Timothy Le Bon Date: Mon, 2 Dec 2024 16:56:03 +0100 Subject: [PATCH] chore: testing pipeline --- Jenkinsfile | 140 ++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 103 insertions(+), 37 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index a91c5f6c4c0..43f66279177 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -10,6 +10,7 @@ pipeline { environment { CREDENTIALS = credentials('GITHUB_TOKEN_WEB') WIRE_BOT_SECRET = credentials('JENKINSBOT_WEBAPP_DEV') + webappApplicationPath = 'https:/wire-webapp-precommit.zinfra.io/' } stages { @@ -55,58 +56,123 @@ pipeline { } } } + } sleep(20) return false - } - } - - } - } - post { - failure { - script { - wireSend(secret: env.WIRE_BOT_SECRET, message: "❌ **$BRANCH_NAME**\n[$CHANGE_TITLE](${CHANGE_URL})\nBuild aborted or failed! See [Github Actions](" + env.GITHUB_ACTION_URL + ')') } } } } - stage('Smoke Tests') { - when { - expression { BRANCH_NAME ==~ /PR-[0-9]+/ } - } - steps { - script { - def files = [] - withAWS(region: 'eu-west-1', credentials: 'S3_CREDENTIALS') { - files = s3FindFiles bucket: 'z-lohika', path: "artifacts/megazord/android/reloaded/staging/compat/$BRANCH_NAME/", onlyFiles: true, glob: '*.apk' - } - files.sort { a, b -> a.lastModified <=> b.lastModified } - if (files.size() < 1) { - error('Could not find any apk at provided location!') - } else { - def lastModifiedFileName = files[-1].name - build job: 'android_reloaded_smoke', parameters: [string(name: 'AppBuildNumber', value: "artifacts/megazord/android/reloaded/staging/compat/$BRANCH_NAME/${lastModifiedFileName}"), string(name: 'TAGS', value: '@smoke'), string(name: 'Branch', value: 'android_dev')] +stage('Wait for GitHub action to finish') { + when { + expression { BRANCH_NAME ==~ /PR-[0-9]+/ } + } + timeout(time: 20, unit: 'MINUTES') { + waitUntil { + def output = sh label: 'Get runs', returnStdout: true, script: 'curl -u ${CREDENTIALS} https://api.github.com/repos/wireapp/wire-webapp/actions/workflows/79043704/runs' + def json = readJSON text: output + def runs = json['workflow_runs'] + echo('Looking for hash ' + commit_hash) + for (run in runs) { + if (run['head_sha'] == commit_hash) { + echo('Found hash ' + run['head_sha']) + echo('conclusion: ' + run['conclusion']) + // conclusion can be: success, failure, neutral, cancelled, skipped, timed_out, or action_required + if (run['conclusion'] == 'success') { + return true + } else if (run['conclusion'] == 'failure') { + error("❌ **Build failed for branch '${GIT_BRANCH_WEBAPP}'** See [Github Actions](" + run['url'] + ')') + } else if (run['conclusion'] == 'cancelled') { + error("⚠️ **Build aborted for branch '${GIT_BRANCH_WEBAPP}'** See [Github Actions](" + run['url'] + ')') + } } } + sleep(20) + return false } - post { - unsuccessful { - script { - wireSend(secret: env.WIRE_BOT_SECRET, message: "❌ **$BRANCH_NAME**\n[$CHANGE_TITLE](${CHANGE_URL})\nQA-Jenkins - Smoke tests failed (see above report)") + } + } + + stage('Check deployment') { + try { + // Wait until deployment has finished (20 retries * 30 seconds == 10 minutes) + timeout(time: 10, unit: 'MINUTES') { + waitUntil { + def randomid = sh returnStdout: true, script: 'uuidgen' + randomid = randomid.trim() + def current_hash = sh returnStdout: true, script: "curl '${webappApplicationPath}commit?v=${randomid}'" + current_hash = current_hash.trim() + echo('Current version is: ' + current_hash) + if (current_hash == commit_hash) { + echo('Deployment finished.') + return true } + env.MESSAGE = 'Current hash still is ' + current_hash + ' and not ' + commit_hash + sh "echo '${MESSAGE}' > deployment.log" + sleep(30) + return false } } + } catch (e) { + def reason = sh returnStdout: true, script: 'cat deployment.log || echo ""' + wireSend secret: "$jenkinsbot_secret", message: "❌ **Deployment failed on** ${webappApplicationPath}\n${commit_msg}\n**Reason:** ${e}\n${reason}" + error("$e / $reason") } + wireSend secret: "$jenkinsbot_secret", message: "✅ **Deployment successful on** ${webappApplicationPath}\n${commit_msg}" } - post { - success { - script { - if (env.BRANCH_NAME ==~ /PR-[0-9]+/) { - wireSend(secret: env.WIRE_BOT_SECRET, message: "✅ **$BRANCH_NAME**\n[$CHANGE_TITLE](${CHANGE_URL})\nQA-Jenkins - Smoke tests successful (see above report)") - } - } - } + stage('Trigger smoke test') { + build job: 'Webapp_Smoke_Chrome', parameters: [string(name: 'TAGS', value: '@smoke'), string(name: 'GIT_BRANCH', value: 'dev'), string(name: 'webappApplicationPath', value: "$webappApplicationPath")], wait: false } } + post { + success { + wireSend secret: "$jenkinsbot_secret", message: "✅ **Build finished for branch '$GIT_BRANCH_WEBAPP'**\n${commit_msg}" + } + failure { + script { + wireSend(secret: env.WIRE_BOT_SECRET, message: "❌ **$BRANCH_NAME**\n[$CHANGE_TITLE](${CHANGE_URL})\nBuild aborted or failed! See [Github Actions](" + env.GITHUB_ACTION_URL + ')') + } + } + } + +// stage('Smoke Tests') { +// when { +// expression { BRANCH_NAME ==~ /PR-[0-9]+/ } +// } +// steps { +// script { +// def files = [] +// withAWS(region: 'eu-west-1', credentials: 'S3_CREDENTIALS') { +// files = s3FindFiles bucket: 'z-lohika', path: "artifacts/megazord/android/reloaded/staging/compat/$BRANCH_NAME/", onlyFiles: true, glob: '*.apk' +// } +// files.sort { a, b -> a.lastModified <=> b.lastModified } +// if (files.size() < 1) { +// error('Could not find any apk at provided location!') +// } else { +// def lastModifiedFileName = files[-1].name +// build job: 'android_reloaded_smoke', parameters: [string(name: 'AppBuildNumber', value: "artifacts/megazord/android/reloaded/staging/compat/$BRANCH_NAME/${lastModifiedFileName}"), string(name: 'TAGS', value: '@smoke'), string(name: 'Branch', value: 'android_dev')] +// } +// } +// } +// post { +// unsuccessful { +// script { +// wireSend(secret: env.WIRE_BOT_SECRET, message: "❌ **$BRANCH_NAME**\n[$CHANGE_TITLE](${CHANGE_URL})\nQA-Jenkins - Smoke tests failed (see above report)") +// } +// } +// } +// } +// } + +// post { +// success { +// script { +// if (env.BRANCH_NAME ==~ /PR-[0-9]+/) { +// wireSend(secret: env.WIRE_BOT_SECRET, message: "✅ **$BRANCH_NAME**\n[$CHANGE_TITLE](${CHANGE_URL})\nQA-Jenkins - Smoke tests successful (see above report)") +// } +// } +// } +// } +// }