From ff530db4f8cc0105b7cfe8595199807a0c3f9d00 Mon Sep 17 00:00:00 2001 From: Timothy Le Bon Date: Tue, 10 Dec 2024 18:07:45 +0100 Subject: [PATCH] chore: ongoing changes to pipeline --- Jenkinsfile | 119 +++++++++++++++++++++++++++------------------------- 1 file changed, 62 insertions(+), 57 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index c70240b1d42..3a1847e289c 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -1,25 +1,25 @@ @NonCPS def checkWorkflowRun(Map run, String commitHash) { - final String headSha = run['head_sha'] - if (headSha == commitHash) { - echo("Found hash ${headSha}") - final String conclusion = run['conclusion'] - echo("conclusion: ${conclusion}") + final String headSha = run['head_sha'] + if (headSha == commitHash) { + echo("Found hash ${headSha}") + final String conclusion = run['conclusion'] + echo("conclusion: ${conclusion}") - switch(conclusion) { + switch (conclusion) { case 'success': - return true + return true case 'failure': - final String url = run['url'] - error("❌ **Build failed for branch '${GIT_BRANCH_WEBAPP}'** See [Github Actions](${url})") - break + final String url = run['url'] + error("❌ **Build failed for branch '${GIT_BRANCH_WEBAPP}'** See [Github Actions](${url})") + break case 'cancelled': - final String url = run['url'] - error("⚠️ **Build aborted for branch '${GIT_BRANCH_WEBAPP}'** See [Github Actions](${url})") - break - } + final String url = run['url'] + error("⚠️ **Build aborted for branch '${GIT_BRANCH_WEBAPP}'** See [Github Actions](${url})") + break } - return false + } + return false } pipeline { @@ -92,62 +92,67 @@ pipeline { steps { when { expression { BRANCH_NAME ==~ /PR-[0-9]+/ } } timeout(time: 15, unit: 'MINUTES') { - script { - final String apiUrl = 'https://api.github.com/repos/wireapp/wire-webapp/actions/workflows/79043704/runs' - final String curlCmd = "curl -u \${CREDENTIALS} ${apiUrl}" - waitUntil { - final String output = sh(label: 'Check workflow', returnStdout: true, script: curlCmd) - final Object jsonData = readJSON(text: output) - final List workflowRuns = jsonData['workflow_runs'] - echo("Looking for hash ${commit_hash}") + script { + final String apiUrl = 'https://api.github.com/repos/wireapp/wire-webapp/actions/workflows/79043704/runs' + final String curlCmd = "curl -u \${CREDENTIALS} ${apiUrl}" + waitUntil { + final String output = sh(label: 'Check workflow', returnStdout: true, script: curlCmd) + final Object jsonData = readJSON(text: output) + final List workflowRuns = jsonData['workflow_runs'] + echo("Looking for hash ${commit_hash}") - return workflowRuns.any { run -> checkWorkflowRun(run, commit_hash) } - } - } + return workflowRuns.any { run -> checkWorkflowRun(run, commit_hash) } + } + } } } } 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 + steps { + script { + 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 + } } - 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") - } + 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}" + } + } wireSend secret: "$jenkinsbot_secret", message: "✅ **Deployment successful on** ${webappApplicationPath}\n${commit_msg}" + } } 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 - } + steps { + 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 + ')') + 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 + ')') + } } + } + } }