Thursday, October 6, 2022

teams notification using github actions

 sample workflow file I used for a project.

# This is a basic workflow to help you get started with Actions

name: test1

# Controls when the workflow will run
on:
  # Triggers the workflow on push or pull request events but only for the "MasterLayer2" branch
  push:
    branches: [ "test1" ]


  # Allows you to run this workflow manually from the Actions tab
  workflow_dispatch:

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
  # This workflow contains a single job called "build"
  build:
    # The type of runner that the job will run on
    runs-on: windows-latest

    # Steps represent a sequence of tasks that will be executed as part of the job
    steps:
      - name: Notify in Teams Channel
        if: failure()
        shell: powershell
        run: |
          $body=@"
          {
              "@type": "MessageCard",
              "@context": "http://schema.org/extensions",
              "themeColor": "d73600",
              "summary": "Notification Summary",
              "sections": [{
                  "facts": [{
                      "name": "Workflow Name",
                      "value": "${env:GITHUB_WORKFLOW}"
                  },{
                      "name": "Execution branch",
                      "value": "${env:GITHUB_REF_NAME}"
                  }, {
                      "name": "Workflow Build Number",
                      "value": "${{ github.run_number }}"
                  }, {
                      "name": "Repository",
                      "value": "${{ github.repository }}"
                  }, {
                      "name": "Commit Message",
                      "value": "${{ github.event.head_commit.message }}"
                  }, {
                      "name": "Job name",
                      "value": "${{ github.job }}"
                  },{
                      "name": "Job status",
                      "value": "${{ job.status }}"
                  }],
                  "markdown": true
              }]
          }
          "@
          Invoke-RestMethod -Method post -ContentType 'Application/Json' -Body $body -Uri ${{ secrets.MICROSOFT_TEAMS_WEBHOOK_URI }}


github actions concurrency explained: https://www.youtube.com/watch?v=PZ_A0QiLvz8


full details to teams: https://www.youtube.com/watch?v=NKO4vNuGKYc


https://github.com/marketplace/actions/microsoft-teams-notification

https://dreitier.com/de/knowledge-base/building-twelve-factor-apps/build-release-run/github-actions/notifying-microsoft-teams-with-github-actions




https://docs.microsoft.com/en-us/microsoftteams/platform/webhooks-and-connectors/how-to/connectors-using?tabs=PowerShell



https://dreitier.com/de/knowledge-base/building-twelve-factor-apps/build-release-run/github-actions/notifying-microsoft-teams-with-github-actions

No comments:

Post a Comment