Versions Compared

Key

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

...

Code Block
languagejs
title.gitlab-ci.yml
# Official language image. Look for the different tagged releases at:
# https://hub.docker.com/r/library/python/tags/
image: python:3.12.2

# Change pip's cache directory to be inside the project directory since we can
# only cache local items.
variables:
  PIP_CACHE_DIR: "$CI_PROJECT_DIR/.cache/pip"

# https://pip.pypa.io/en/stable/topics/caching/
cache:
  paths:
    - .cache/pip

stages:
  - execute_automated_tests
  - upload_test_results

before_script:
  - python --version ; pip --version  # For debugging
  - pip install virtualenv
  - virtualenv venv
  - source venv/bin/activate
  - pip install -r requirements.txt
  - apt-get update


test:
  stage: execute_automated_tests
  before_script: | 
    set -e
    apt-get install -yqq unzip curl
    # Install Chrome & chromedriver
    curl -sS -o - https://dl.google.com/linux/linux_signing_key.pub | apt-key add -
    echo "deb https://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google.list
    apt update && apt install google-chrome-stable -y
    wget -O /tmp/chromedriver.zip https://storage.googleapis.com/chrome-for-testing-public/121.0.6167.85/linux64/chromedriver-linux64.zip
    ls -la /tmp/chromedriver.zip
    unzip -j /tmp/chromedriver.zip chromedriver-linux64/chromedriver -d /usr/local/bin/
    nohup python demoapp/server.py &
  script: |
    chromedriver -v && \
    pip install -r requirements.txt && \
    robot -x junit.xml -o output.xml login_tests || true
  allow_failure: true
  artifacts:
    paths:
      - output.xml
    when: always

  
upload_results_to_xray:
  stage: upload_test_results
  script:
    - | 
    echo "uploading results to Xray..."
    export token=$(- 'curl -H "Content-Type: applicationmultipart/jsonform-data" -X POSTu $XRAY_USERNAME:$XRAY_PASSWORD --dataF "{ \"client_id\": \"$client_id\",\"client_secret\": \"$client_secret\" }" https://xray.cloud.getxray.app/api/v2/authenticate| tr -d '"')
    curl -H "Content-Type: text/xml" -H "Authorization: Bearer $token" -F "file=@output.xml" "https://xray.cloud.getxray.app/api/v2/import/execution/junit?projectKey=$project_key" 
  file=@output.xml" "$XRAY_SERVER_URL/rest/raven/2.0/import/execution/robot?projectKey=$PROJECT_KEY"'
    - echo "done"
  dependencies:
  - test


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

However, we do not want to have the JIRA credentials hardcoded in GitLab's configuration file. Therefore, we'll use some secret variables defined in GitLab project settin

However, we do not want to have the Xray API credentials hardcoded in GitLab's configuration file. Therefore, we'll use some environment variables defined in project settings, including::

  • XRAY_SERVER_URL: Jira's base URL
  • XRAY_USERNAME: the username used on the REST API
  • XRAY_PASSWORD: the password used on the REST API
  • PROJECT_KEY: Jira project
  • client_id: the client_id associated with the API key created in the Xray cloud instance 
  • client_secret: the client_secret associated with the API key created in the Xray cloud instance
  • project_key: the client_secret associated with the API key created in the Xray cloud instance


Info
titlePlease note

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

Image RemovedImage Added



In .gitlab-ci.yml a "step" must be included that will use "curl" in order to first obtain a token and then finally submit the results to the REST API, using that token.

...