1
0
mirror of https://github.com/SAP/jenkins-library.git synced 2025-01-04 04:07:16 +02:00

generate docs for slackSendNotification step (#592)

This commit is contained in:
Christopher Fenner 2019-03-26 12:14:29 +01:00 committed by GitHub
parent a6c8a8d94d
commit f8c8e81958
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 51 additions and 60 deletions

View File

@ -1,73 +1,33 @@
# slackSendNotification
# ${docGenStepName}
## 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.
## ${docGenDescription}
## Prerequisites
Installed and configured [Jenkins Slack plugin](https://github.com/jenkinsci/slack-plugin).
* Installed and configured [Jenkins Slack plugin](https://github.com/jenkinsci/slack-plugin).
## ${docGenParameters}
## ${docGenConfiguration}
## Example
Usage of pipeline step:
```groovy
try {
stage('..') {..}
stage('..') {..}
stage('..') {..}
currentBuild.result = 'SUCCESS'
} catch (Throwable err) {
currentBuild.result = 'FAILURE'
throw err
} finally {
stage('report') {
slackSendNotification script: this
pipeline {
agent any
stages {
stage('Build') {
steps {
echo "do something"
}
}
}
post {
always {
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`](commonPipelineEnvironment.md) 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](../configuration.md).
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|

View File

@ -1,6 +1,7 @@
import static com.sap.piper.Prerequisites.checkScript
import com.sap.piper.ConfigurationHelper
import com.sap.piper.GenerateDocumentation
import com.sap.piper.Utils
import groovy.transform.Field
import groovy.text.SimpleTemplateEngine
@ -9,14 +10,44 @@ import groovy.text.SimpleTemplateEngine
@Field Set GENERAL_CONFIG_KEYS = []
@Field Set STEP_CONFIG_KEYS = GENERAL_CONFIG_KEYS.plus([
/**
* Allows overriding the Slack Plugin Integration Base Url specified in the global configuration.
*/
'baseUrl',
/**
* Allows overriding of the default massaging channel from the plugin configuration.
*/
'channel',
/**
* Defines the message color`color` defines the message color.
* @possibleValues one of `good`, `warning`, `danger`, or any hex color code (eg. `#439FE0`)
*/
'color',
/**
* The credentials id for the Slack token.
* @possibleValues Jenkins credentials id
*/
'credentialsId',
/**
* Send a custom message into the Slack channel.
*/
'message'
])
@Field Set PARAMETER_KEYS = STEP_CONFIG_KEYS
/**
* 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.
*/
@GenerateDocumentation
void call(Map parameters = [:]) {
handlePipelineStepErrors (stepName: STEP_NAME, stepParameters: parameters) {
def utils = parameters.juStabUtils ?: new Utils()