Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

  1. create a new rule (i.e., the one that will actually create a new Test Execution and trigger the previous rule) and define the "When" (i.e. when it should be triggered) to be "Manual Trigger"
  2. create an action using the "Send web request" template to make the authentication request and obtain a token to be used on the GraphQL operations; we need a client_id and a client_secret (please see how to create API keys).
  3. save the response in a variable (e.g., "token")
  4. make a GraphQL query to obtain the details of the Test Execution and its results
    1. Use the GraphQL API, namely the getTestExecution function. We'll need the issue id of the Test Execution that was already completed; 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, if we want to set it later on, under the "Issue Fields" section of your Jira administration. 

    2. Escape the GraphQL query (e.g., using the online GraphQL to JSON Body Converter tool)


      Code Block
      titlesample GraphQL query
      collapsetrue
      {
        "query": "{ getTestExecution(issueId: \"{{issue.id}}\") { issueId jira(fields: [\"key\",\"customfield_10033\"]) testRuns(limit: 100){ results{ status{ name } test { issueId jira(fields: [\"key\"]) } } } testEnvironments testPlans(limit: 1) { results{ issueId jira(fields: [\"key\"]) } } }}"
      }
  5. get the linked Test Plan issue id and store it in a variable
    1. Code Block
      {{webResponse.body.data.getTestExecution.testPlans.results.get(0).issueId}}
  6. get the associated Test Environments and store it in a variable
    1. Code Block
      {{webResponse.body.data.getTestExecution.testEnvironments.asJsonStringArray}}
  7. post-process it and store it in another variable, as we need to escape some characters to embed the Test Environments on the GraphQL request later on
    1. Code Block
      {{testEnvironments.replaceAll("\"","\\\\\"")}}
  8. get all the failed tests and store them in a variable (note that this is an approximate value as GraphQL results can be limited and paginated)
    1. Code Block
      {{webResponse.body.data.getTestExecution.testRuns.results.status.name.match(".*(FAILED).*").size|0}} 
  9. store the issue ids of the failed tests in a variable (note that this is an approximate value as GraphQL results can be limited and paginated) 
    1. Code Block
      {{#webResponse.body.data.getTestExecution.testRuns.results}}{{#if(equals(status.name,"FAILED")) }}"{{test.issueId}}" {{/}}{{/}}
  10. post-process it and store it in another variable, as we need to escape some characters to embed the Test issue ids on the GraphQL request later on
    1. Code Block
      {{testIds.split(" ").join(",")}}
    2. Code Block
      {{testIds.replaceAll("\"","\\\\\"")}}
  11. use an "IF" block to only proceed if there are failed tests
  12. make a GraphQL API request to create a new Test Execution containing just the Tests that failed
    1. Code Block
      {
        "query": "mutation { createTestExecution( testEnvironments: {{escapedTestEnvironments}}, testIssueIds: [{{escapedTestIds}}], jira: { fields: { summary: \"dummy Test Execution\", project: {key: \"{{project.key}}\"} } } ) { testExecution { issueId jira(fields: [\"key\"]) } warnings }}"
      }
  13. store the issue id of the new Test Execution in a variable
    1. Code Block
      {{webResponse.body.data.createTestExecution.testExecution.issueId}}
  14. use the "Send web request" action to trigger the incoming webhook we defined in the "Automation rule 1" mentioned at start  
    1. Code Block
      {
        "issues": [
          "{{newTestExecutionId}}",
          "{{testPlanId}}"
        ],
        "testExecutionId": "{{newTestExecutionId}}",
        "testPlanId": "{{testPlanId}}",
        "token": "{{token}}"
      }

...