2020-04-25 23:00:08 +03:00
|
|
|
|
<?php
|
2020-10-02 00:11:13 +02:00
|
|
|
|
/*
|
|
|
|
|
## Installing
|
|
|
|
|
|
|
|
|
|
Require ms-teams recipe in your `deploy.php` file:
|
|
|
|
|
|
|
|
|
|
Setup:
|
|
|
|
|
1. Open MS Teams
|
|
|
|
|
2. Navigate to Teams section
|
|
|
|
|
3. Select existing or create new team
|
|
|
|
|
4. Select existing or create new channel
|
2023-03-02 08:51:01 +01:00
|
|
|
|
5. Hover over channel to get three dots, click, in menu select "Connectors"
|
2020-10-02 00:11:13 +02:00
|
|
|
|
6. Search for and configure "Incoming Webhook"
|
|
|
|
|
7. Confirm/create and copy your Webhook URL
|
|
|
|
|
8. Setup deploy.php
|
|
|
|
|
Add in header:
|
|
|
|
|
```php
|
|
|
|
|
require 'contrib/ms-teams.php';
|
|
|
|
|
set('teams_webhook', 'https://outlook.office.com/webhook/...');
|
|
|
|
|
```
|
|
|
|
|
Add in content:
|
|
|
|
|
```php
|
|
|
|
|
before('deploy', 'teams:notify');
|
2020-10-29 23:16:36 +01:00
|
|
|
|
after('deploy:success', 'teams:notify:success');
|
2020-10-02 00:11:13 +02:00
|
|
|
|
after('deploy:failed', 'teams:notify:failure');
|
|
|
|
|
```
|
|
|
|
|
9.) Sip your coffee
|
|
|
|
|
|
|
|
|
|
## Configuration
|
|
|
|
|
|
|
|
|
|
- `teams_webhook` – teams incoming webhook url, **required**
|
|
|
|
|
```
|
|
|
|
|
set('teams_webhook', 'https://outlook.office.com/webhook/...');
|
|
|
|
|
```
|
|
|
|
|
- `teams_title` – the title of application, default `{{application}}`
|
|
|
|
|
- `teams_text` – notification message template, markdown supported
|
|
|
|
|
```
|
|
|
|
|
set('teams_text', '_{{user}}_ deploying `{{branch}}` to *{{target}}*');
|
|
|
|
|
```
|
|
|
|
|
- `teams_success_text` – success template, default:
|
|
|
|
|
```
|
|
|
|
|
set('teams_success_text', 'Deploy to *{{target}}* successful');
|
|
|
|
|
```
|
|
|
|
|
- `teams_failure_text` – failure template, default:
|
|
|
|
|
```
|
|
|
|
|
set('teams_failure_text', 'Deploy to *{{target}}* failed');
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
- `teams_color` – color's attachment
|
|
|
|
|
- `teams_success_color` – success color's attachment
|
|
|
|
|
- `teams_failure_color` – failure color's attachment
|
|
|
|
|
|
|
|
|
|
## Usage
|
2020-04-25 23:00:08 +03:00
|
|
|
|
|
2020-10-02 00:11:13 +02:00
|
|
|
|
If you want to notify only about beginning of deployment add this line only:
|
|
|
|
|
|
|
|
|
|
```php
|
|
|
|
|
before('deploy', 'teams:notify');
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
If you want to notify about successful end of deployment add this too:
|
|
|
|
|
|
|
|
|
|
```php
|
2020-10-29 23:16:36 +01:00
|
|
|
|
after('deploy:success', 'teams:notify:success');
|
2020-10-02 00:11:13 +02:00
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
If you want to notify about failed deployment add this too:
|
|
|
|
|
|
|
|
|
|
```php
|
|
|
|
|
after('deploy:failed', 'teams:notify:failure');
|
|
|
|
|
```
|
|
|
|
|
*/
|
2020-04-25 23:00:08 +03:00
|
|
|
|
namespace Deployer;
|
|
|
|
|
|
|
|
|
|
use Deployer\Utility\Httpie;
|
|
|
|
|
|
|
|
|
|
// Title of project
|
|
|
|
|
set('teams_title', function () {
|
|
|
|
|
return get('application', 'Project');
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// Deploy message
|
|
|
|
|
set('teams_text', '_{{user}}_ deploying `{{branch}}` to *{{target}}*');
|
|
|
|
|
set('teams_success_text', 'Deploy to *{{target}}* successful');
|
|
|
|
|
set('teams_failure_text', 'Deploy to *{{target}}* failed');
|
|
|
|
|
|
|
|
|
|
// Color of attachment
|
|
|
|
|
set('teams_color', '#4d91f7');
|
|
|
|
|
set('teams_success_color', '#00c100');
|
|
|
|
|
set('teams_failure_color', '#ff0909');
|
|
|
|
|
|
2021-11-08 22:59:39 +01:00
|
|
|
|
desc('Notifies Teams');
|
2020-04-25 23:00:08 +03:00
|
|
|
|
task('teams:notify', function () {
|
|
|
|
|
if (!get('teams_webhook', false)) {
|
2023-03-02 08:49:57 +01:00
|
|
|
|
warning('No MS Teams webhook configured');
|
2020-04-25 23:00:08 +03:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2021-11-07 10:49:16 +01:00
|
|
|
|
Httpie::post(get('teams_webhook'))->jsonBody([
|
2020-04-25 23:00:08 +03:00
|
|
|
|
"themeColor" => get('teams_color'),
|
|
|
|
|
'text' => get('teams_text')
|
|
|
|
|
])->send();
|
|
|
|
|
})
|
|
|
|
|
->once()
|
|
|
|
|
->hidden();
|
|
|
|
|
|
2021-11-08 22:59:39 +01:00
|
|
|
|
desc('Notifies Teams about deploy finish');
|
2020-04-25 23:00:08 +03:00
|
|
|
|
task('teams:notify:success', function () {
|
|
|
|
|
if (!get('teams_webhook', false)) {
|
2023-03-02 08:49:57 +01:00
|
|
|
|
warning('No MS Teams webhook configured');
|
2020-04-25 23:00:08 +03:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2021-11-07 10:49:16 +01:00
|
|
|
|
Httpie::post(get('teams_webhook'))->jsonBody([
|
2020-04-25 23:00:08 +03:00
|
|
|
|
"themeColor" => get('teams_success_color'),
|
|
|
|
|
'text' => get('teams_success_text')
|
|
|
|
|
])->send();
|
|
|
|
|
})
|
|
|
|
|
->once()
|
|
|
|
|
->hidden();
|
|
|
|
|
|
2021-11-08 22:59:39 +01:00
|
|
|
|
desc('Notifies Teams about deploy failure');
|
2020-04-25 23:00:08 +03:00
|
|
|
|
task('teams:notify:failure', function () {
|
|
|
|
|
if (!get('teams_webhook', false)) {
|
2023-03-02 08:49:57 +01:00
|
|
|
|
warning('No MS Teams webhook configured');
|
2020-04-25 23:00:08 +03:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2021-11-07 10:49:16 +01:00
|
|
|
|
Httpie::post(get('teams_webhook'))->jsonBody([
|
2020-04-25 23:00:08 +03:00
|
|
|
|
"themeColor" => get('teams_failure_color'),
|
|
|
|
|
'text' => get('teams_failure_text')
|
|
|
|
|
])->send();
|
|
|
|
|
})
|
|
|
|
|
->once()
|
|
|
|
|
->hidden();
|