-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Reorganise jenkinsfile twig templates and extract slack notification …
…script (#136)
- Loading branch information
1 parent
52fa261
commit 6b2b173
Showing
9 changed files
with
52 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
application/overlay/_twig/Jenkinsfile/slack-notification.twig
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
script { | ||
def message = "{% if @('jenkins.notifications.global.full_build_name') %}${env.JOB_NAME}{% else %}${env.JOB_BASE_NAME}{% endif %} #${env.BUILD_NUMBER} - Failure after ${currentBuild.durationString.minus(' and counting')} (<${env.RUN_DISPLAY_URL}|View Build>)" | ||
def fallbackMessages = [ message ] | ||
def fields = [] | ||
|
||
{% if @('jenkins.notifications.global.branch_link_template') and @('jenkins.notifications.global.commit_link_template') %} | ||
def shortCommitHash = "${GIT_COMMIT}".substring(0, 7) | ||
def commitLink = "commit <{{ @('jenkins.notifications.global.commit_link_template') }}".replace('GIT_COMMIT', GIT_COMMIT) + "|${shortCommitHash}>" | ||
def gitMessage = "Branch <{{ @('jenkins.notifications.global.branch_link_template') }}".replace('GIT_BRANCH', GIT_BRANCH) + "|${GIT_BRANCH}> at ${commitLink}" | ||
|
||
if (env.CHANGE_URL) { | ||
// Jenkins builds pull requests by merging the pull request branch into the pull request's target branch, | ||
// so we build on commits that do not technically exist and can't link to them. | ||
gitMessage = "<${env.CHANGE_URL}|{{ @('jenkins.notifications.global.change_request_name') }} #${env.CHANGE_ID}> ${env.CHANGE_TITLE}{% if @('jenkins.notifications.global.change_request_build_on_merge') %} - merged into target branch " + "<{{ @('jenkins.notifications.global.branch_link_template') }}".replace('GIT_BRANCH', CHANGE_TARGET) + "|${CHANGE_TARGET}>{% endif %}" | ||
} | ||
fields << [ | ||
title: 'Source', | ||
value: gitMessage, | ||
short: false | ||
] | ||
fallbackMessages << gitMessage | ||
{% endif %} | ||
|
||
def failureMessage = failureMessages.join("\n") | ||
if (failureMessage) { | ||
fields << [ | ||
title: 'Reason(s)', | ||
value: failureMessage, | ||
short: false | ||
] | ||
fallbackMessages << failureMessage | ||
} | ||
def attachments = [ | ||
[ | ||
text: message, | ||
fallback: fallbackMessages.join("\n"), | ||
color: 'danger', | ||
fields: fields | ||
] | ||
] | ||
|
||
slackSend (channel: '{{ @('jenkins.notifications.slack.channel') }}', color: 'danger', attachments: attachments, tokenCredentialId: '{{ @('jenkins.notifications.slack.token_credential_id') }}') | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,14 @@ | ||
{% set blocks = 'application/overlay/_twig/Jenkinsfile/' %} | ||
|
||
{% if @('jenkins.tests.isolated') %} | ||
{% include blocks ~ 'setup.twig' %} | ||
{% include blocks ~ 'test.twig' %} | ||
{% include blocks ~ 'build.twig' %} | ||
{% include blocks ~ 'test-end-to-end.twig' %} | ||
{% include blocks ~ 'stages/setup.twig' %} | ||
{% include blocks ~ 'stages/test.twig' %} | ||
{% include blocks ~ 'stages/build.twig' %} | ||
{% include blocks ~ 'stages/test-end-to-end.twig' %} | ||
{% else %} | ||
{% include blocks ~ 'build.twig' %} | ||
{% include blocks ~ 'test.twig' %} | ||
{% include blocks ~ 'stages/build.twig' %} | ||
{% include blocks ~ 'stages/test.twig' %} | ||
{% endif %} | ||
|
||
{% include blocks ~ 'publish.twig' %} | ||
{% include blocks ~ 'deploy.twig' %} | ||
{% include blocks ~ 'stages/publish.twig' %} | ||
{% include blocks ~ 'stages/deploy.twig' %} |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.