Skip to content

Commit 3d995d9

Browse files
authored
Allow Continue on Failure (#4098)
Since a Teams notification is not necessarily an essential part of a deploy, we should allow users to continue the deploy should a notification fail to send.
1 parent 4bc695c commit 3d995d9

File tree

2 files changed

+54
-12
lines changed

2 files changed

+54
-12
lines changed

contrib/ms-teams.php

Lines changed: 40 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,9 @@
8080
return get('application', 'Project');
8181
});
8282

83+
// Allow Continue on Failure
84+
set('teams_failure_continue', false);
85+
8386
// Deploy message
8487
set('teams_text', '_{{user}}_ deploying `{{what}}` to *{{where}}*');
8588
set('teams_success_text', 'Deploy to *{{where}}* successful');
@@ -97,10 +100,19 @@
97100
return;
98101
}
99102

100-
Httpie::post(get('teams_webhook'))->jsonBody([
101-
"themeColor" => get('teams_color'),
102-
'text' => get('teams_text'),
103-
])->send();
103+
try {
104+
Httpie::post(get('teams_webhook'))->jsonBody([
105+
"themeColor" => get('teams_color'),
106+
'text' => get('teams_text'),
107+
])->send();
108+
} catch (\Exception $e) {
109+
if (get('teams_failure_continue', false)) {
110+
warning('Error sending Teams Notification: ' . $e->getMessage());
111+
} else {
112+
throw $e;
113+
}
114+
}
115+
104116
})
105117
->once()
106118
->hidden();
@@ -112,10 +124,18 @@
112124
return;
113125
}
114126

115-
Httpie::post(get('teams_webhook'))->jsonBody([
116-
"themeColor" => get('teams_success_color'),
117-
'text' => get('teams_success_text'),
118-
])->send();
127+
try {
128+
Httpie::post(get('teams_webhook'))->jsonBody([
129+
"themeColor" => get('teams_success_color'),
130+
'text' => get('teams_success_text'),
131+
])->send();
132+
} catch (\Exception $e) {
133+
if (get('teams_failure_continue', false)) {
134+
warning('Error sending Teams Notification: ' . $e->getMessage());
135+
} else {
136+
throw $e;
137+
}
138+
}
119139
})
120140
->once()
121141
->hidden();
@@ -127,10 +147,18 @@
127147
return;
128148
}
129149

130-
Httpie::post(get('teams_webhook'))->jsonBody([
131-
"themeColor" => get('teams_failure_color'),
132-
'text' => get('teams_failure_text'),
133-
])->send();
150+
try {
151+
Httpie::post(get('teams_webhook'))->jsonBody([
152+
"themeColor" => get('teams_failure_color'),
153+
'text' => get('teams_failure_text'),
154+
])->send();
155+
} catch (\Exception $e) {
156+
if (get('teams_failure_continue', false)) {
157+
warning('Error sending Teams Notification: ' . $e->getMessage());
158+
} else {
159+
throw $e;
160+
}
161+
}
134162
})
135163
->once()
136164
->hidden();

docs/contrib/ms-teams.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ after('deploy:failed', 'teams:notify:failure');
4141
set('teams_webhook', 'https://outlook.office.com/webhook/...');
4242
```
4343
- `teams_title` – the title of application, default `{{application}}`
44+
- `teams_failure_continue` - allow deploys to continue on failure
45+
```
46+
set('teams_failure_continue', true);
47+
```
4448
- `teams_text` – notification message template, markdown supported
4549
```
4650
set('teams_text', '_{{user}}_ deploying `{{what}}` to *{{where}}*');
@@ -56,6 +60,7 @@ after('deploy:failed', 'teams:notify:failure');
5660
- `teams_color` – color's attachment
5761
- `teams_success_color` – success color's attachment
5862
- `teams_failure_color` – failure color's attachment
63+
5964
## Usage
6065
If you want to notify only about beginning of deployment add this line only:
6166
```php
@@ -81,6 +86,15 @@ Title of project
8186
return get('application', 'Project');
8287
```
8388

89+
### teams_failure_continue
90+
[Source](https://github.com/deployphp/deployer/blob/master/contrib/ms-teams.php#L79)
91+
92+
Allow Continue on Failure
93+
94+
```php title="Continue on Failure"
95+
return get('teams_failure_continue', false)
96+
```
97+
8498

8599
### teams_text
86100
[Source](https://github.com/deployphp/deployer/blob/master/contrib/ms-teams.php#L84)

0 commit comments

Comments
 (0)