Versions Compared

Key

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

...

To implement the continuous integration, we'll implement a specific workflow for it and store it in .github/workflows/CI-jira-cloud-example-using-action.yaml.

We’ll use the actions/checkout action to checkout the code from our repository to the virtual environment.  This action is one of the "standard" actions provided by GitHub (check full list here).

...

We use Maven to build and run the tests.

In order to submit those results to Xray, we'll just need to invoke the REST API (as detailed in Import Execution Results - REST); we can do that using an utility (e.g. "curl") or we can use the open-source, community provided, GitHub Action "xray-action" which is easier to use.

The following example uses "xray-action" to submit test automation results to Xray.


Code Block
languageyml
title.github/workflows/CI-jira-cloud-example-using-action.yaml
name: CI (Jira cloud example with GH action)
on: [push]
jobs:
  build:
    runs-on: ubuntu-latest
        
    steps:
    - uses: actions/checkout@v1
    - name: Set up Java
      uses: actions/setup-java@v1
      with:
        java-version: '1.8'  
    - name: Cache Maven packages
      uses: actions/cache@v2
      with:
        path: ~/.m2
        key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
        restore-keys: ${{ runner.os }}-m2
    - name: Build with Maven
      run: mvn clean compile test --file pom.xml
    - name: Submit results to Xray
      uses: mikepenz/xray-action@v0.9.4
      with:
        username: ${{ secrets.client_id }}
        password: ${{ secrets.client_secret }}
        testFormat: "junit"
        testPaths: "**/surefire-reports/*.xml"
        projectKey: "CALC"


As mentioned, you could also do it by yourself using "curl", for example, in case you want to.

Code Block
languageyml
title.github/workflows/CI-jira-cloud-example.yaml
collapsetrue
name: CI (Jira cloud example)
on: [push]
jobs:
  build:
    runs-on: ubuntu-latest

    steps:
    - uses: actions/checkout@v1
    - name: Set up Java
      uses: actions/setup-java@v1
      with:
        java-version: '1.8'
    - name: Cache Maven packages
      uses: actions/cache@v2
      with:
        path: ~/.m2
        key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
        restore-keys: ${{ runner.os }}-m2
    - name: Build with Maven
      run: mvn clean compile test --file pom.xml
    - name: Get Xray Cloud API token
      env:
        CLIENT_ID: ${{ secrets.client_id }}
        CLIENT_SECRET: ${{ secrets.client_secret }}
      id: xray-token
      run: |
        echo ::set-output name=XRAY_TOKEN::$(curl -H "Content-Type: application/json" -X POST --data "{ \"client_id\": \"$CLIENT_ID\",\"client_secret\": \"$CLIENT_SECRET\" }" https://xray.cloud.xpand-it.com/api/v1/authenticate| tr -d '"')
    - name: Submit results to Xray
      run: 'curl -H "Content-Type: text/xml" -H "Authorization: Bearer ${{ steps.xray-token.outputs.XRAY_TOKEN }}" --data @target/surefire-reports/TEST-com.xpand.java.CalcTest.xml  "https://xray.cloud.xpand-it.com/api/v2/import/execution/junit?projectKey=CALC"'

In order to submit those results to Xray, we'll just need to invoke the REST API (as detailed in Import Execution Results - REST).


However, we do not want to have the Xray credentials Note that the Xray credentials are not hardcoded in the configuration file. Therefore, we'll We use some secret variables defined in GitHub project settings.

...

Info
titlePlease note

The user associated with Xray's API key must have permission to Create Test and Test Execution Issues.


  Image RemovedImage Added


Some parameters may be hardcoded on the HTTP request used to submit the result; this is up to you to define what makes sense to be explicit on the request or what could be set, for example, using a secret variable in GitHub.

...

To see the runs for your workflows (i.e. workflow runs), you may access Actions tab in your repository browser.

Image RemovedImage Added  


Clicking in the last event that triggered the workflow run will show the details .(screenshots using "xray-action" and using "curl" utility).

Image Added   Image Added   Image Removed


In Jira, Xray now shows the results of the automated tests in a brand new Test Execution issue. Test issues corresponding to each test method will be auto-provisioned, if they don't exist yet; otherwise, results will be reported against existing Tests.

...