Add TEAMS to ArgoCD Notifications? Never easier and your Sitecore dev team will thank you!

Hello, fellow developers! May the Sitecore force be with you 🙂

In our last adventure, ArgoCD Notifications is your friend when you need to notify deployment status from your Sitecore K8 cluster, I unveiled the power of ArgoCD Notifications. Your trusty sidekick for broadcasting deployment statuses from your Sitecore Kubernetes cluster using Slack as our loyal messenger.

Today, our journey continues as we add another ally to our arsenal: Microsoft Teams. Together, we’ll keep our dev team in the loop, ensuring they know when our deployments soar smoothly into the digital skies. 😊

Let’s Dive In!

Our first task involves some teamwork with Microsoft Teams. We’ll create a special channel, our deployment command center, called SitecoreTest. To bridge the gap between ArgoCD Notifications and Teams, we’ll set up a webhook. It’s simple – just right-click on the new channel, select “Connectors,” choose “Incoming Webhook”.

Provide a name for the webhook(I’m lazy, we’ll give it the same name as the channel).

We’re all set. Make sure to copy that magical webhook URL – we’ll need it later.

Tip: If you misplace the webhook URL, don’t worry! Just head back to your channel, select “Connectors,” click on “Configured” under MANAGE, and there it is, waiting for you.

Fantastic, we have our webhook! Now, let’s integrate it into ArgoCD Notifications.

A Dash of Magic and a Pinch of Caution

Before we proceed, a word of caution. Be mindful of the ArgoCD Notifications version you install. The journey might get bumpy if you choose the wrong one. Make sure to use version v1.2.1, it will support Microsoft Teams.

kubectl apply -n argocd -f https://raw.githubusercontent.com/argoproj-labs/argocd-notifications/release-1.2/manifests/install.yaml

With our trusty version in place, let’s update the secret, argocd-notifications-secret, by invoking this magic spell:

kubectl edit secret --namespace argocd argocd-notifications-secret

Now, add your webhook to the secret’s enchanting data section, ensuring it’s encoded in the ancient language of base64 🙂

apiVersion: v1
kind: Secret
metadata:
  name: argocd-notifications-secret
data:
  channel-teams-url: <base64 encoded webhook>

Next, let’s update the configmap, argocd-notifications-cm. We’ll sprinkle in the Teams channel (SitecoreTest) and the webhook. Prepare your wand and chant this incantation:

kubectl edit configmaps --namespace argocd argocd-notifications-cm

Add the following essence to the configmap, the teams channel(SitecoreTest) and the webhook($channel-teams-url)

apiVersion: v1
data:
  service.teams: "recipientUrls: \n  SitecoreTest: $channel-teams-url\n"

We have one more thing to do, and that is to update our ArgoCD applications. Similar to what we did for SLACK (in the previous adventure). Let’s use the same “sync event” we did for SLACK:
on-sync-succeeded => ArgoCD succeeded to sync/deploy to the pod
on-sync-failed => ArgoCD did not succeed to sync/deploy to the pod

Here is the manifest for the ArgoCD application:

apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
  name: nextjsproxy-someapp
  namespace: argocd
  annotations:
    notifications.argoproj.io/subscribe.on-sync-succeeded.teams: SitecoreTest #Teams Channel
    notifications.argoproj.io/subscribe.on-sync-failed.teams: SitecoreTest #Teams Channel 
   

Voila! The Spell is Cast

Our ArgoCD Notifications are now attuned to Microsoft Teams, ready to weave their notifications into the digital tapestry. Let’s have a look 🙂

Wonderful 🙂

But wait, there’s more 😉

A Touch of Personalization

Ever wanted your messages to sparkle with personalization? We can add a touch of flair by altering the message templates. For instance, notice how “Website” in our messages presents a glorious URL to the test website? Let me show you the magic behind it.

On the ArgoCD application, we can infuse extra essence by using labels, like defining the website.

apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
  name: nextjsproxy-someapp
  namespace: argocd
  annotations:
    notifications.argoproj.io/subscribe.on-sync-succeeded.teams: SitecoreTest #Teams Channel
    notifications.argoproj.io/subscribe.on-sync-failed.teams: SitecoreTest #Teams Channel 
  labels:
    website: someapp.test.sandbox.com
   

Now, to alter our messages we have to change the message templates. The templates are located in the configmap,  argocd-notifications-cm. Let’s edit:

kubectl edit configmaps --namespace argocd argocd-notifications-cm
apiVersion: v1
data:
  service.teams: "recipientUrls: \n  SitecoreTest: $channel-teams-url\n"
  template.app-created: |
    email:
      subject: Application {{.app.metadata.name}} has been created.
    message: Application {{.app.metadata.name}} has been created.
    teams:
      title: Application {{.app.metadata.name}} has been created.
   ...  

And there it is – template.app-sync-succeeded, the masterpiece of our notifications. Witness the seamless fusion of labels into the message:

template.app-sync-succeeded: |
    email:
      subject: Application {{.app.metadata.name}} has been successfully synced.
    message: |
      {{if eq .serviceType "slack"}}:white_check_mark:{{end}} Application {{.app.metadata.name}} has been successfully synced.
      Have a nice day 🙂
    slack:
      ...
    teams:
      facts: |
        [{
          "name": "Sync Status",
          "value": "{{.app.status.sync.status}}"
        },
        {
          "name": "Synced at",
          "value": "{{.app.status.operationState.finishedAt}}"
        },
        {
          "name": "Website",
          "value": "https://{{.app.metadata.labels.website}}"
        },
        {
          "name": "Repository",
          "value": "https://{{.app.metadata.labels.repo}}"
        }
        {{range $index, $c := .app.status.conditions}}
          {{if not $index}},{{end}}
          {{if $index}},{{end}}
          {
            "name": "{{$c.type}}",
            "value": "{{$c.message}}"
          }
        {{end}}
        ]
      potentialAction: 
      themeColor: '#000080'
      title: Application {{.app.metadata.name}} has been successfully synced

And that’s it!

That’s all for now folks 😊


Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.