JavaScript GitHub action to send message to channel(s) in Microsoft Teams using webhook URL(s)
Send a one line message
Additional configuration enables title, status and actor name labels, title background color, buttons that re-direct to run and commit URLs
Add incoming webhook URL for Teams in GitHub secrets
To send a minimal message, add the following in your workflow YAML
E.g.,
steps:
- uses: neonidian/teams-notify-build-status@v3
with:
webhookUrl: ${{ secrets.TEAMS_INCOMING_WEBHOOK_URL }} # Secret name is "TEAMS_INCOMING_WEBHOOK_URL"
message: Workflow run passed !!
E.g.,
steps:
- uses: neonidian/teams-notify-build-status@v3
with:
webhookUrl: | # Send to multiple channels in MS Teams
${{ secrets.TEAMS_INCOMING_WEBHOOK_URL_1 }}
${{ secrets.TEAMS_INCOMING_WEBHOOK_URL_2 }}
title: Unit Tests # Specify a title header
titleBackgroundColor: ${{ steps.unitTest.outcome }} # Specify title background color. 'unitTest' is the ID of a step
status: ${{ steps.unitTest.outcome }} # Specify what should be displayed in the status label
message: >-
Unit tests have been run for version ${{ steps.versioning.outputs.semver }} # 'versioning' is the ID of the steps that creates versioning
env: # Enable actor labels and buttons using environment variables
SHOULD_DISPLAY_ACTOR_LABEL: true
SHOULD_DISPLAY_VIEW_RUN_BUTTON: true
SHOULD_DISPLAY_VIEW_COMMIT_BUTTON: true
See the actions tab in your GitHub repository for runs of this action! 🚀
# | Input ID | Required | Description |
---|---|---|---|
1 | webhookUrl | Yes | Teams webhook URL(s). If more than 1 webhook URL, use YAML multi-line strings |
2 | message | Yes | Message to be sent |
3 | title | No | Title of the card (displays at the top with a larger text) |
4 | titleBackgroundColor | No | Background color of the title section. Allowed values: 'success', 'green', 'failure', 'red', 'cancelled', 'yellow','skipped', 'blue' success, failure, cancelled, skipped can be used dynamically in the workflow using job or step context. E.g., ${{ job.status }} or ${{ steps.<step_id>.outcome }} See GitHub docs for more info |
5 | status | No | Status of a step or a job, or a custom text |
# | Environment variable | Allowed values | Default value | Description |
---|---|---|---|---|
1 | SHOULD_DISPLAY_VIEW_RUN_BUTTON | 'true' or 'false' | false | Clicking on this button redirects to the attempt of the workflow run page in GitHub |
2 | SHOULD_DISPLAY_VIEW_COMMIT_BUTTON | 'true' or 'false' | false | Clicking on this button redirects to SHA commit page in GitHub |
3 | SHOULD_DISPLAY_ACTOR_LABEL | 'true' or 'false' | false | Label to display the username of the workflow initiator |
steps:
- uses: neonidian/teams-notify-build-status@v3
if: ${{ !success() }} # For other statuses, see https://docs.github.com/en/actions/learn-github-actions/expressions#status-check-functions
with:
webhookUrl: ${{ secrets.TEAMS_INCOMING_WEBHOOK_URL }}
message: >-
Failed to publish artifact version ${{ steps.versioning.outputs.semver }}
status: Failure
env:
SHOULD_DISPLAY_VIEW_RUN_BUTTON: true
true
steps:
- uses: neonidian/teams-notify-build-status@v3
needs: [ unitTests, systemTests ] # IDs of jobs
if: ${{ job.status == 'failure' }} # Same as 'failure()'
with:
webhookUrl: ${{ secrets.TEAMS_INCOMING_WEBHOOK_URL }}
title: >-
[Repository link](${{ github.server_url }}/${{ github.repository }})
message: Test run failed
status: ${{ job.status }}
env:
SHOULD_DISPLAY_VIEW_RUN_BUTTON: true
SHOULD_DISPLAY_VIEW_COMMIT_BUTTON: true
SHOULD_DISPLAY_ACTOR_LABEL: true
steps:
- uses: neonidian/teams-notify-build-status@v3
if: always()
with:
webhookUrl: |
${{ secrets.TEAMS_INCOMING_WEBHOOK_URL_1 }}
${{ secrets.TEAMS_INCOMING_WEBHOOK_URL_2 }}
${{ secrets.TEAMS_INCOMING_WEBHOOK_URL_3 }}
message: Workflow has been run
titleBackgroundColor: ${{ job.status }}
env:
SHOULD_DISPLAY_VIEW_COMMIT_BUTTON: true
status = "failure", "View run" and "View commit" buttons enabled
status = "skipped", "View run" and "View commit" buttons are not enabled
No status input provided, title = "Only with title and view run button" with "View Run" button enabled
status = "skipped", only "View run" is enabled
status = "cancelled", only "View commit" button enabled
Status = "BUILD SUCCESSFUL" which is a custom status not defined in GitHub statuses. Font colour is set to default in case of custom status
titleBackgroundColor = "failure", view run button enabled
title and status inputs provided, titleBackgroundColor = "yellow", view run and view commit buttons enabled
Environment variable SHOULD_DISPLAY_ACTOR_LABEL
set to true
; set title
Mobile device screenshot (iOS)