2

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

2 Answers 2

7

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.

0

Just add when: always in the artifacts section

test:
  stage: test
  allow_failure: true
  image: mcr.microsoft.com/playwright:v1.35.1-focal 

  script:
    - |
      npm install ci
      npm install -D @playwright/test
      npm i -D @playwright/test allure-playwright
      npm install mysql
      npm ci
      npx playwright install --with-deps
      npx playwright install msedge
      npx playwright install chrome
      npx playwright test
      
  timeout: 10 hours #overriding the default gitlab runner timeout optional

  artifacts:
    paths: 
     - ./playwright-report/
     - ./Screenshot/
     - ./Reports/
            
    when: always
    expire_in: 7 days 

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.