Configure build job in GitLab CI

Configure build jobs

The examples below show the following jobs configurations:

  1. Single build job.
  2. Multi job workflow.

Common settings

For any type of build job you need to define the following variables:


variables:
  ALLURE_LAUNCH_NAME: "${CI_PROJECT_NAME} - ${CI_COMMIT_SHORT_SHA}"
  ALLURE_LAUNCH_TAGS: "regular, ${CI_COMMIT_REF_NAME}"
  ALLURE_TESTPLAN_PATH: "./testplan.json"
  ALLURE_RESULTS: "allure-results"

Single build job configuration

  1. allurectl should be used to upload the test results
stages:
  - test

variables:
  ALLURE_LAUNCH_NAME: "${CI_PROJECT_NAME} - ${CI_COMMIT_SHORT_SHA}" #mandatory
  ALLURE_LAUNCH_TAGS: "regular, ${CI_COMMIT_REF_NAME}" #mandatory
  ALLURE_TESTPLAN_PATH: "./testplan.json" #mandatory
  ALLURE_RESULTS: "allure-results" #mandatory
  TESTS_ENDPOINT: "https://never.never.never.let.you.down" # preferably set here as an env
  TESTS_BROWSER: "firefox" # preferably set here as an env
  TESTS_BRANCH: ${CI_COMMIT_REF_NAME} # preferably set here as an env

test:
  image: gradle
  stage: test
  before_script:
    - wget https://github.com/allure-framework/allurectl/releases/latest/download/allurectl_linux_386 -O ./allurectl
    - chmod +x ./allurectl
  script:
    - ./allurectl job-run plan --output-file ${ALLURE_TESTPLAN_PATH} # where to save testplan.json
    - ./allurectl watch -- ./gradlew clean test #allurectl runs your tests and watches allure-result dir and uploads results in real time

  1. Execute your pipeline

Multi job workflow

  1. allurectl should be used to upload the test results
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
    - pip install pytest allure-pytest

  script:
    - echo "$ALLURE_RESULTS"
    - ls -l $ALLURE_RESULTS || true
    - ./allurectl job-run plan --output-file ${ALLURE_TESTPLAN_PATH}
    - if test -f ${ALLURE_TESTPLAN_PATH}; then cat ${ALLURE_TESTPLAN_PATH}; fi
    - ./allurectl watch -- ./tests1.sh
    - echo "$ALLURE_RESULTS" || true
    - ls -l $ALLURE_RESULTS || true

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
    - pip install pytest allure-pytest
  script:
    - echo "$ALLURE_RESULTS"
    - ls -l $ALLURE_RESULTS || true
    - ./allurectl job-run plan --output-file ${ALLURE_TESTPLAN_PATH}
    - if test -f ${ALLURE_TESTPLAN_PATH}; then cat ${ALLURE_TESTPLAN_PATH}; fi
    - ./allurectl watch -- ./tests2.sh
    - echo "$ALLURE_RESULTS"
    - ls -l $ALLURE_RESULTS
  1. Execute your pipeline

Next step - import test results

Jump to import of test results