Skip to content

Commit

Permalink
chore: ongoing changes to pipeline
Browse files Browse the repository at this point in the history
  • Loading branch information
tlebon committed Dec 10, 2024
1 parent b54737c commit ff530db
Showing 1 changed file with 62 additions and 57 deletions.
119 changes: 62 additions & 57 deletions Jenkinsfile
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down Expand Up @@ -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 + ')')
}
}
}
}
}

0 comments on commit ff530db

Please sign in to comment.