mirror of
https://github.com/SAP/jenkins-library.git
synced 2025-02-05 13:25:19 +02:00
fix(mailSendNotification): do not send recovery notifications on first build (#3978)
* fix(mailSendNotification): do not send recovery notifications on first build * added unit tests
This commit is contained in:
parent
f5b6580e4c
commit
50ac1a3ab5
@ -244,4 +244,57 @@ user3@domain.com noreply+github@domain.com'''
|
||||
assertThat(credentials, hasItem(''))
|
||||
assertJobStatusSuccess()
|
||||
}
|
||||
|
||||
@Test
|
||||
void testSendNotificationMailOnFirstBuild() throws Exception {
|
||||
def emailExtCalls = []
|
||||
def buildMock = [
|
||||
fullProjectName: 'testProjectName',
|
||||
displayName: 'testDisplayName',
|
||||
result: 'SUCCESS',
|
||||
getPreviousBuild: {
|
||||
return null
|
||||
}
|
||||
]
|
||||
nullScript.currentBuild = buildMock
|
||||
helper.registerAllowedMethod('emailext', [Map.class], { map ->
|
||||
emailExtCalls.add(map)
|
||||
return ''
|
||||
})
|
||||
|
||||
stepRule.step.mailSendNotification(
|
||||
script: nullScript,
|
||||
notifyCulprits: false,
|
||||
gitUrl: 'git@github.domain.com:IndustryCloudFoundation/pipeline-test-node.git'
|
||||
)
|
||||
|
||||
assertThat(emailExtCalls, hasSize(0))
|
||||
}
|
||||
|
||||
@Test
|
||||
void testSendNotificationMailOnRecovery() throws Exception {
|
||||
def emailExtCalls = []
|
||||
def buildMock = [
|
||||
fullProjectName: 'testProjectName',
|
||||
displayName: 'testDisplayName',
|
||||
result: 'SUCCESS',
|
||||
getPreviousBuild: {
|
||||
return [result: 'FAILURE']
|
||||
}
|
||||
]
|
||||
nullScript.currentBuild = buildMock
|
||||
helper.registerAllowedMethod('emailext', [Map.class], { map ->
|
||||
emailExtCalls.add(map)
|
||||
return ''
|
||||
})
|
||||
|
||||
stepRule.step.mailSendNotification(
|
||||
script: nullScript,
|
||||
notifyCulprits: false,
|
||||
gitUrl: 'git@github.domain.com:IndustryCloudFoundation/pipeline-test-node.git'
|
||||
)
|
||||
|
||||
assertThat(emailExtCalls, hasSize(1))
|
||||
assertThat(emailExtCalls[0].subject, is("SUCCESS: Build testProjectName testDisplayName is back to normal"))
|
||||
}
|
||||
}
|
||||
|
@ -252,5 +252,11 @@ def getDistinctRecipients(recipients){
|
||||
}
|
||||
|
||||
def hasRecovered(buildResult, currentBuild){
|
||||
return buildResult == 'SUCCESS' && currentBuild.getPreviousBuild()?.result != 'SUCCESS'
|
||||
def previousBuild = currentBuild.getPreviousBuild()
|
||||
|
||||
if (previousBuild) {
|
||||
return buildResult == 'SUCCESS' && previousBuild.result != 'SUCCESS'
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user