gitlab Cypress 生成诱惑报告

时间:2021-05-31 16:26:14

标签: continuous-integration gitlab-ci cypress pipeline allure

我的 .gitlab-ci.yml 文件如下:

image: cypress/base:14.16.0

stages:
  - test
test:
  stage: test
  script:
    - npm install
    - npm run scripts

脚本在哪里 --> cypress run --spec cypress/integration/UI/myScript.feature

在脚本参数后添加另一个命令以生成诱惑报告时,gitlab 管道向我抛出了未设置 JAVA 主路径生成诱惑报告的错误。

ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH

所以我将我的脚本更新为这样的:

image: cypress/base:14.16.0

stages:
  - test
  - allure

test:
  stage: test
  script:
    - npm install
    - npm run clean:allure
    - npm run scripts

allure_report:
  stage: allure
  when: always
  image: timbru31/java-node
  dependencies: 
    - test
  script:
    - npm install
    - npm run generate-allure-report
  artifacts:
    when: always
    paths:
      - cypress/reportsAllure/allure-report/
      - cypress/reportsAllure/allure-results/

其中 generate-allure-report 是 --> allure generate cypress/reportsAllure/allure-results --clean -o cypress/reportsAllure/allure-report

但是这里生成了空报告。有谁知道我需要从第一阶段传递到下一个阶段以生成魅力报告的工件吗?

1 个答案:

答案 0 :(得分:1)

这对我有用,但我使用的是默认文件夹位置,因此您需要更改与工件路径相同的位置并在适当的地方附加 -o folder/allure-report

stages:
  - test
  - allure
  - deploy

cache:
  key: ${CI_COMMIT_REF_SLUG}
  paths:
    - node_modules

.download_history: &download_history
  after_script:
    - apt-get install -y unzip
    - mkdir backup && cd backup || true
    - "curl --location --output report.zip --request GET \"https://gitlab.com/api/v4/projects/${CI_PROJECT_ID}/jobs/artifacts/master/download?job=pages\" --header \"Authorization: Bearer ${CI_DEPLOY_TOKEN}\" || true"
    - (unzip report.zip) || true
    - cd ../
    - (cp -r backup/public/history/ allure-results/history/) || true


.test_template: &test_template
  image: 
    name: cypress/included:7.5.0
    entrypoint: [""]
  stage: test
  variables:
    CY_RUN_ID: ${CI_JOB_ID}
  script:
    - export CYPRESS_VIDEO=false
    - npm install
    - ./node_modules/.bin/cypress run --headless --env allure=true
  artifacts:
    when: always
    paths:
      - allure-results/

smoke:
  <<: *test_template
  <<: *download_history

allure_report:
  stage: allure
  when: always
  image: 
    name: ubuntu:latest
    entrypoint: [""]
  dependencies: 
    - smoke
  variables:
    DEBIAN_FRONTEND: noninteractive
    TZ: Europe/London
  before_script:
    - apt-get update
    - apt-get install -y default-jdk wget unzip 
    - mkdir /work/
    - wget https://github.com/allure-framework/allure2/releases/download/2.13.8/allure-2.13.8.zip -P /work/
    - unzip /work/allure-2.13.8.zip -d /work/
  script:
    - /work/allure-2.13.8/bin/allure generate allure-results --clean -o allure-report
  artifacts:
    when: always
    paths:
      - allure-report/
      - allure-results/
  only:
    - master

pages:
  stage: deploy
  when: always
  dependencies:
    - allure_report
  script:
    - mv allure-report/ public/
  artifacts:
    paths:
      - public
    expire_in: 30 days
  only:
    - master