-1

I have this yml file

test1:
  stage: test
  #
  rules:
    - when: 
      if: $TEST_ENABLE == "ON"
  script:
    - ........ logic to run tests ............
    - C:\tpt.exe --tpt_output="xml:logs.xml"
  artifacts:
    paths:
      - targets\test\reports\*.html

I have this stage test1 that runs several test cases and once that is finished i create a logs.xml file that stores all the data like duration, result, testcase number, etc. Currently when the pipeline is triggered the test cases fails but the test stage passes. I think there is no link between pipeline and the xml.

In the logs.xml i can see that result=ERROR. Now I want to parse this inside the pipeline and tell pipeline if result=ERROR then fail the stage. How can I do that? can someone guide me here? Thanks in advance.

What I have tried but does not work:

script:
    - ........ logic to run tests ............
    - C:\tpt.exe --tpt_output="xml:logs.xml"
    - test -f logs.xml && grep -L "ERROR" logs.xml
PforPython
  • 58
  • 7

2 Answers2

0

Gitlab job fails when a non-zero exit code is returned also if you want to combine mutiple commands in a script and return if it fails or not. You'll need to put them into parenthesis.
I'll try the following :

script:
  - ....
  - (test -f logs.xml && grep -iwc "ERROR" logs.xml)
Raymond A
  • 763
  • 1
  • 12
  • 29
  • This does not work error - "The token '&&' is not a valid statement separator in this version." – PforPython Mar 13 '23 at 14:17
  • Your error might be linked to this https://stackoverflow.com/a/66433504 . Alternatively you can omit the testing of the file if you're always generating it. – Raymond A Mar 13 '23 at 14:27
0

found the solution:

script:
  - ........ logic to run tests ............
  - C:\tpt.exe --tpt_output="xml:logs.xml"
  - if (Select-String -Path logs.xml -Pattern "result=ERROR") {  
  xit 1 }
PforPython
  • 58
  • 7