Test results upload from GitLab

Test results upload from GitLab

GitLab upload workflow uses allurectl. to upload the test results.

Authenticate GitLab build jobs

Authentication token

For a user on Allure TestOps side you need to create API token.

This API token will be used by GitLab to authenticate on Allure TestOps server.

  1. Log in to Allure TestOps with account you are going to use to upload test results.
  2. Go to user’s profile.

Allure go to profile

  1. In the section API tokens click a green button that says Create.
  2. Name your API token and click Submit. Always give meaningful names to all the configuration parameters.

Allure go to profile

Allure will randomly generate the token and show you in modal window.

  1. Copy the token and save it in a safe place as it cannot be retrieved by Allure TestOps means.

Configure GitLab project to upload the test results

Add your Allure server instance information to Gitlab’ configuration

  1. Navigate to CI / CD project settings

    Gitlab menu

  2. Navigate to Variables section

  3. Create 3 variables as shown below

    1. ALLURE_ENDPOINT - Allure TestOps URL (for example: http://testops.company.com).
    2. ALLURE_TOKEN - Allure TestOps token created in the previous steps.
    3. ALLURE_PROJECT_ID - Allure TestOps project ID to which you are going to upload the results results.

Gitlab CI-CD Variables

Build jobs

Single job pipeline

stages:
  - test

variables:
  ALLURE_LAUNCH_NAME: "${CI_PROJECT_NAME} - ${CI_COMMIT_SHORT_SHA}"
  ALLURE_LAUNCH_TAGS: "${CI_COMMIT_REF_NAME}, gitlab, demo, pytest, skip-live-doc, ignore"
  ALLURE_TESTPLAN_PATH: "./testplan.json"
  ALLURE_RESULTS: "./allure-results"
  TESTS_ENDPOINT: "https://pytest.never.never.never.give.up"
  TESTS_BROWSER: "firefox"
  TESTS_BRANCH: ${CI_COMMIT_REF_NAME}

test:
  image: python:3.9.1
  stage: test
  before_script:
    - wget https://github.com/allure-framework/allurectl/releases/latest/download/allurectl_linux_386 -O ./allurectl
    - chmod +x ./allurectl
    - pip install pytest allure-pytest
  script:
    - echo ${ALLURE_USER_USED}
    - ./allurectl --version
    - ./allurectl job-run plan --output-file ${ALLURE_TESTPLAN_PATH}
    - ./allurectl watch -- pytest --alluredir=${ALLURE_RESULTS} || true

- ./allurectl job-run plan --output-file ${ALLURE_TESTPLAN_PATH} is required to make selective run of tests possible.

Second condition for the selective rerun is the support of this feature in the Allure FrameWork adaptor for your test framework.

Multi-job pipeline

stages:
  - unit
  - func

variables:
  ALLURE_LAUNCH_NAME: "${CI_PROJECT_NAME} - ${CI_COMMIT_SHORT_SHA}"
  ALLURE_LAUNCH_TAGS: "${CI_COMMIT_REF_NAME}, gitlab, multijob, fake-results"
  ALLURE_TESTPLAN_PATH: "./testplan.json"
  ALLURE_RESULTS: "allure-results"
  TESTS_ENDPOINT: "https://never.never.never.let.you.down"
  TESTS_BROWSER: "firefox"
  TESTS_BRANCH: ${CI_COMMIT_REF_NAME}

unit-tests:
  image: python:3.9.1  
  stage: unit
  before_script:
    - wget https://github.com/allure-framework/allurectl/releases/latest/download/allurectl_linux_386 -O ./allurectl
    - chmod +x ./allurectl
    - chmod +x ./tests1.sh
    - ls -l $ALLURE_RESULTS || true

  script:
    - ./allurectl job-run plan --output-file ${ALLURE_TESTPLAN_PATH}
    - ./allurectl watch -- ./tests1.sh

func-test:
  image: python:3.9.1
  stage: func
  before_script:
    - wget https://github.com/allure-framework/allurectl/releases/latest/download/allurectl_linux_386 -O ./allurectl
    - chmod +x ./allurectl
    - chmod +x ./tests2.sh
  script:
    - ./allurectl job-run plan --output-file ${ALLURE_TESTPLAN_PATH}
    - ./allurectl watch -- ./tests2.sh