Gitlab CI - Publish Failed Test Results to Pages

纵饮孤独 提交于 2020-02-23 04:15:08

问题


I'm creating a simple java project using Gradle which generates a test report (i.e. BDD Cucumber, JUnit, etc.). This project is deployed to Gitlab where the project is built as part of the Gitlab CI process.

My JUnit reports are generated in the folder build/reports/tests/test/ relative to the project path (as an index.html and some CSS files, etc.).

How do I configure my .gitlab-ci.yml to publish the content of build/reports/tests/test/ to the Gitlab Pages even after my test cases fail?

This is what I have in my .gitlab-ci.yml: (My repo can be found HERE)

Version 1: Doesn't publish anything to pages

image: java:8-jdk

stages:
  - test

before_script:
  - export GRADLE_USER_HOME=`pwd`/.gradle

test:
  stage: test
  script:
    - mkdir public
    - ./gradlew test

  artifacts:
    paths:
      - build/reports/tests/test/
  only:
  - master

after_script:
  - mv build/reports/tests/test/* public

Version 2: Doesn't execute the deploy stage since test has failed.

image: java:8-jdk

stages:
  - test
  - deploy

before_script:
  - export GRADLE_USER_HOME=`pwd`/.gradle

test:
  stage: test
  script:
    - ./gradlew test

  artifacts:
    paths:
      - build/reports/tests/test/

 pages:
   stage: deploy
   dependencies:
     - test
   script:
   - mkdir public
   - mv build/reports/tests/test/* public
   artifacts:
     paths:
      - public

  only:
  - master

回答1:


I solved the issue by adding the when: always at the end of my pages stage. It now executes the stage regardless of exit code from the dependent stage.



来源:https://stackoverflow.com/questions/51296500/gitlab-ci-publish-failed-test-results-to-pages

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!