1

I'm running Jenkins parameterized jobs with the following pipeline configuration of allure step:

stage('Generate reports') {
    allure([
        includeProperties: false,
        jdk              : '',
        properties       : [],
        reportBuildPolicy: 'ALWAYS'
        results          : [[path: webdriverTestResultsPath], [path: unitTestResultsPath]]])
}

Build's parameters, which are set before starting the job, become available within getEnv() in my tests. I'd like to show some of them in the Environment section of Allure report's dashboard. For instance, there is a HOST build parameter which specifies the base application url.

Is there a way to do this?

Bohdan Nesteruk
  • 794
  • 17
  • 42

2 Answers2

3

Disclosure: I've created Java library which deals with this issue: https://github.com/AutomatedOwl/allure-environment-writer

It uses TransformerFactory to write the environment.xml to the allure-results path in any stage of the test. It also checks for the directory existence in case running from cleaned build.

Usage example:

import static com.github.automatedowl.tools.AllureEnvironmentWriter.allureEnvironmentWriter;

public class SomeTests {

    @BeforeSuite
    void setAllureEnvironment() {
        allureEnvironmentWriter(
                ImmutableMap.<String, String>builder()
                        .put("Browser", "Chrome")
                        .put("Browser.Version", "70.0.3538.77")
                        .put("URL", "http://testjs.site88.net")
                        .build(), System.getProperty("user.dir")
                        + "/allure-results/");
    }

    @Test
    void someTest() {
        Assert.assertTrue(true);
    }
}
AutomatedOwl
  • 1,039
  • 1
  • 8
  • 14
2

You can also utilize environment.properties file, the format of the file:

Browser=Chrome
Browser.Version=63.0
Stand=Production

source: https://docs.qameta.io/allure/#_environment

File location: allure-results directory (eg. target/allure-results)

You can generate the file in your pipeline before the allure report is generated.

Gitlab pipeline example:

publish-reports:
  extends:
    - .runner
  stage: report-results
  artifacts:
    paths:
      - allure-results
    expire_in: 14 days
  before_script:
    - mkdir -p target/allure-results || true  
  script:
    - echo "============== PREPARE ALLURE ENV VARIABLES FILE =========================="
    - echo "Browser=${VAR_BROWSER}" > target/allure-results/environment.properties
    - echo "BrowserVersion=${VAR_BROWSER_VERSION}" >> target/allure-results/environment.properties
    - echo "Stand=${VAR_STAND}" >> target/allure-results/environment.properties

    - echo "============== GENERATING ALLURE REPORTS STATIC WEB PAGE ================="
    - cp -rp allure-results target/allure-results/
    - mvn --settings ${M2SETTINGS} allure:report 
emksk
  • 71
  • 5