I want the PublishTestResults@2 task to run ONLY if the previous task script (which runs unit tests) actually ran.
- If I use
condition: succeededOrFailed()thenPublishTestResults@2runs even if the previous step did not run - I thought this was whatcondition: always()was for.
- How does one make a task contingent on the previous task even if the previous task failed?
- What is the difference between
always()andsucceededOrFailed()?
# This step only runs if the previous step was successful - OK
- script: |
cd $(System.DefaultWorkingDirectory)/application/src
yarn test:unit --silent --ci --reporters=jest-junit
displayName: 'Jest Unit Tests'
env:
JEST_JUNIT_OUTPUT_DIR: $(System.DefaultWorkingDirectory)/testresults
JEST_JUNIT_OUTPUT_NAME: 'jest-junit.xml'
# This step ALWAYS runs - NO
# This step should ONLY run if the previous step RAN (success OR fail)
- task: PublishTestResults@2
displayName: 'Frontend Test results'
condition: succeededOrFailed()
inputs:
testResultsFormat: JUnit
searchFolder: $(System.DefaultWorkingDirectory)/testresults
testResultsFiles: 'jest-junit.xml'
testRunTitle: 'Frontend Test Results'
mergeTestResults: false
failTaskOnFailedTests: true
UPDATE: I suspect the Publish step "Frontend Test results" is running because the 2 previous steps were NOT run but the one before that was successful:
