Microsoft Teams, or "Teams," is a popular communication platform many development and non-development teams adopt.
Teams use it daily to collaborate, make calls, share information, ask for help, and be notified of certain events to increase visibility of the status of the projects they're working on.
In this article, we'll see an everyday use case: sharing test results with the team in their collaboration tool (i.e., "MS Teams"). However, Xray and Jira's built-in automation capabilities can implement many more use cases.
To integrate with Teams, we can set up an incoming webhook in a channel and use it to send notifications (i.e., "messages").
This common use-case is about sharing information about test results, usually from test automation, to a Teams channel so the team can be aware of testing progress and analyze the results if needed.
At high-level, we will:
|
Use the GraphQL API, namely the getTestExecution function. We'll need the issue id of the Test Execution that was triggered; we can use the smart values feature from Jira automation to obtain it. We need to also obtain the custom field id of the "Revision" custom field under the "Issue Fields" section of your Jira administration.
{ getTestExecution(issueId: "{{issue.id}}") { issueId jira(fields: ["key","customfield_10033"]) testRuns(limit: 100){ results{ status{ name } test { jira(fields: ["key"]) } } } testEnvironments testPlans(limit: 1) { results{ jira(fields: ["key"]) } } } } |
{{webResponse.body.data.getTestExecution.testRuns.results.size|0}} |
{{webResponse.body.data.getTestExecution.testRuns.results.status.name.match(".*(PASSED).*").size|0}} |
{{webResponse.body.data.getTestExecution.testRuns.results.status.name.match(".*(FAILED).*").size|0}} |
{{webResponse.body.data.getTestExecution.testRuns.results.status.name.match(".*(TO DO).*").size|0}} |
{{#=}}{{totalTests}} - {{passedTests}} - {{failedTests}} - {{todoTests}}{{/}} |
{{webResponse.body.data.getTestExecution.testPlans.results.jira.key}} |
{{webResponse.body.data.getTestExecution.testEnvironments.join(",")}} |
{{webResponse.body.data.getTestExecution.testEnvironments.join(",")}} |
As a mere example, for the "failure" image we can use the following one.
https://docs.getxray.app/s/e1tqew/8402/f0863dd17de361916f7914addff17e0432a0be98/_/images/icons/emoticons/error.png |
As a mere example, for the "success" image we can use the following one.
https://docs.getxray.app/s/e1tqew/8402/f0863dd17de361916f7914addff17e0432a0be98/_/images/icons/emoticons/check.png |
{ "@type": "MessageCard", "@context": "http://schema.org/extensions", "themeColor": "0076D7", "summary": "{{issue.summary}}", "sections": [{ "activitySubtitle": "{{issue.summary}}", "activityTitle": "Test results for project {{project.name}}", "activityImage": "{{notificationImageUrl}}", "facts": [ { "name": "Test Execution", "value": "[{{issue.key}}]({{issue.url}})" }, { "name": "Reporter", "value": "{{issue.reporter.displayName}}" }, { "name": "Version", "value": "{{issue.fixVersions.name}}" }, { "name": "Revision", "value": "{{issue.Revision}}" }, { "name": "Test Environment(s)", "value": "{{testEnvironments}}" }, { "name": "Test Plan", "value": "{{testPlanUrl}}" }, { "name": "Total tests", "value": "{{totalTests}}" }, { "name": "Passed tests", "value": "{{passedTests}}" }, { "name": "Failed tests", "value": "{{failedTests}}" }, { "name": "To Do tests", "value": "{{todoTests}}" }, { "name": "Other tests", "value": "{{otherTests}}" }], "markdown": true }] } |