testkube icon indicating copy to clipboard operation
testkube copied to clipboard

Cannot use {{ .ExecutionURL }} in webhook

Open sylock opened this issue 7 months ago • 2 comments

Describe the bug Hello guys. I have a question. I'm trying to use the webhook feature to send notifications to a Microsoft Teams channel. Everything work except that I cannot use the variable ExecutionURL as described here: https://docs.testkube.io/articles/webhooks#additional-top-level-variables Here is my json payload, see the "action" part of it at the end:

{
  "type": "message",
  "attachments": [
    {
      "contentType": "application/vnd.microsoft.card.adaptive",
      "content": {
        "type": "AdaptiveCard",
        "body": [
          {
            "type": "TextBlock",
            "size": "Medium",
            "weight": "Bolder",
            "text": "{{ .TestExecution.TestName }}"
          },
          {
            "type": "ColumnSet",
            "columns": [
              {
                "type": "Column",
                "items": [
                  {
                    "type": "Image",
                    "url": "https://github.com/kubeshop/testkube/raw/develop/assets/logo-rect-blue.png",
                    "altText": "Testkube",
                    "size": "Large",
                    "spacing": "Small",
                    "width": "30px"
                  }
                ],
                "width": "auto"
              },
              {
                "type": "Column",
                "items": [
                  {
                    "type": "TextBlock",
                    "weight": "Bolder",
                    "text": "Status: {{ .TestExecution.ExecutionResult.Status }}",
                    "wrap": true
                  },
                  {
                    "type": "TextBlock",
                    "spacing": "None",
                    "text": "Finished at {{ .TestExecution.EndTime }}",
                    "isSubtle": true,
                    "wrap": true
                  }
                ],
                "width": "stretch"
              }
            ]
          },
          {
            "type": "TextBlock",
            "text": "Test '{{ .TestExecution.Name }}' finished with '{{ .TestExecution.ExecutionResult.Status }}' status. Click on the link below to see the details.",
            "wrap": true
          }
        ],
        "actions": [
          {
            "type": "Action.OpenUrl",
            "title": "Open test",
            "url": "{{ .ExecutionURL }}"
          }
        ],
        "$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
        "version": "1.0"
      }
    }
  ]
}

In the logs I get "can't evaluate field ExecutionURL" but I don't see why :

{
  "level": "info",
  "ts": 1719569310.493662,
  "caller": "event/emitter.go:179",
  "msg": "notification result",
  "listen-on": [
    "end-test-failed"
  ],
  "queue-group": "testkube.sendnotif",
  "selector": "service=notifications",
  "metadata": {
    "events": "[end-test-failed]",
    "headers": "map[]",
    "name": "testkube.sendnotif",
    "payloadObjectField": "",
    "payloadTemplate": "{\r\n  \"type\": \"message\",\r\n  \"attachments\": [\r\n    {\r\n      \"contentType\": \"application/vnd.microsoft.card.adaptive\",\r\n      \"content\": {\r\n        \"type\": \"AdaptiveCard\",\r\n        \"body\": [\r\n          {\r\n            \"type\": \"TextBlock\",\r\n            \"size\": \"Medium\",\r\n            \"weight\": \"Bolder\",\r\n            \"text\": \"{{ .TestExecution.TestName }}\"\r\n          },\r\n          {\r\n            \"type\": \"ColumnSet\",\r\n            \"columns\": [\r\n              {\r\n                \"type\": \"Column\",\r\n                \"items\": [\r\n                  {\r\n                    \"type\": \"Image\",\r\n                    \"url\": \"https://github.com/kubeshop/testkube/raw/develop/assets/logo-rect-blue.png\",\r\n                    \"altText\": \"Testkube\",\r\n                    \"size\": \"Large\",\r\n                    \"spacing\": \"Small\",\r\n                    \"width\": \"30px\"\r\n                  }\r\n                ],\r\n                \"width\": \"auto\"\r\n              },\r\n              {\r\n                \"type\": \"Column\",\r\n                \"items\": [\r\n                  {\r\n                    \"type\": \"TextBlock\",\r\n                    \"weight\": \"Bolder\",\r\n                    \"text\": \"Status: {{ .TestExecution.ExecutionResult.Status }}\",\r\n                    \"wrap\": true\r\n                  },\r\n                  {\r\n                    \"type\": \"TextBlock\",\r\n                    \"spacing\": \"None\",\r\n                    \"text\": \"Finished at {{ .TestExecution.EndTime }}\",\r\n                    \"isSubtle\": true,\r\n                    \"wrap\": true\r\n                  }\r\n                ],\r\n                \"width\": \"stretch\"\r\n              }\r\n            ]\r\n          },\r\n          {\r\n            \"type\": \"TextBlock\",\r\n            \"text\": \"Test '{{ .TestExecution.Name }}' finished with '{{ .TestExecution.ExecutionResult.Status }}' status. Click on the link below to see the details.\",\r\n            \"wrap\": true\r\n          }\r\n        ],\r\n        \"actions\": [\r\n          {\r\n            \"type\": \"Action.OpenUrl\",\r\n            \"title\": \"Open test\",\r\n            \"url\": \"{{ .ExecutionURL }}\"\r\n          }\r\n        ],\r\n        \"$schema\": \"http://adaptivecards.io/schemas/adaptive-card.json\",\r\n        \"version\": \"1.0\"\r\n      }\r\n    }\r\n  ]\r\n}",
    "selector": "service=notifications",
    "uri": "<Microsoft Team URI_obfuscated>"
  },
  "error": "template: payload:63:23: executing \"payload\" at <.ExecutionURL>: can't evaluate field ExecutionURL in type testkube.Event"
}

sylock avatar Jun 28 '24 11:06 sylock