1
0
mirror of https://github.com/SAP/jenkins-library.git synced 2025-05-31 23:09:34 +02:00
sap-jenkins-library/documentation/docs/steps/slackSendNotification.md
Oliver Nocon 793df723cf add step slackSendNotification (#338)
* add step slackSendNotification

This step allows to send Slack notifications in case of pipeline failures.

* add SWA reporting

* remove allowBuildFailure

* add GENERAL_CONFIG_KEYS

* update STEP_NAME

* add missing import

* fix MD findings

* adjust rule name to be aligned with #455
2019-02-13 16:45:35 +01:00

1.9 KiB

slackSendNotification

Description

Sends notifications to the Slack channel about the build status.

Notification contains:

  • Build status;
  • Repo Owner;
  • Repo Name;
  • Branch Name;
  • Jenkins Build Number;
  • Jenkins Build URL.

Prerequisites

Installed and configured Jenkins Slack plugin.

Example

Usage of pipeline step:

try {
  stage('..') {..}
  stage('..') {..}
  stage('..') {..}
  currentBuild.result = 'SUCCESS'
} catch (Throwable err) {
  currentBuild.result = 'FAILURE'
  throw err
} finally {
  stage('report') {
    slackSendNotification script: this
  }
}

Parameters

parameter mandatory default possible values
script yes
baseUrl no
channel no
color no ${buildStatus == 'SUCCESS'?'#008000':'#E60000'}
credentialsId no
message no

Details

  • script defines the global script environment of the Jenkinsfile run. Typically this is passed to this parameter. This allows the function to access the commonPipelineEnvironment for storing the measured duration.
  • baseUrl allows overriding the Slack Plugin Integration Base Url specified in the global configuration.
  • color defines the message color.
  • If channel is defined another than the default channel will be used.
  • credentialsId defines the Jenkins credentialId which holds the Slack token
  • With parameter message a custom message can be defined which is sent into the Slack channel.

Step configuration

We recommend to define values of step parameters via config.yml file.

In following sections the configuration is possible:

parameter general step stage
script
baseUrl X X
channel X X
color X X
credentialsId X X
message X X