Vladeezy
Vladeezy

Reputation: 187

how to continue running scripts if one of them fails? GITLAB CI

here is my yml file:

stages:
  - testing
  - deploy 

docker_job:
  stage: testing
  tags:
    - docker
  image: atools/chrome-headless:java11-node14-latest 
  
  before_script:
    - npm ci 
    - npx playwright install 
    - npm install allure-commandline --save-dev
  
  script:
    - npm run BookingTestDEV --project=BookingTesting
    - npx playwright test --project=BookEngineTests
    - npm run BookingTestNEO --project=BookingTesting


  after_script:
    - npx allure generate allure-results --clean 
  rules:
      - when: always
  allow_failure: true
  artifacts: 
    when: always
    paths:
      - ./allure-report
    expire_in: 7 day 

pages: 
  stage: deploy
  script:
    - mkdir public 
    - mv ./allure-report/* public
  artifacts:
    paths:
      - public
  rules:
    - when: always
    

if first script - npm run BookingTestDEV --project=BookingTesting fails, other will be skipped, how to run them anyway ? is there any analog of if(): always like on github ?

Upvotes: 9

Views: 5995

Answers (1)

seldesjo
seldesjo

Reputation: 306

In most cases, the pipeline should fail if one of the commands throws an exit code that is not 0. However, in some cases, the rest of the commands should run anyway. A possible solution for this would be to add || true at the end of the command.

For example:

 script:
    - npm run BookingTestDEV --project=BookingTesting || true
    - npx playwright test --project=BookEngineTests
    - npm run BookingTestNEO --project=BookingTesting

Upvotes: 11

Related Questions