Publish Cypress screenshots in Azure DevOps (or externally)

Viewed 730
1 Answers

To publish the screenshots of your failed Cypress tests, you can add the following task to your pipeline definition .yaml file after running your tests. This will publish all created screenshots in the pipeline artifacts of the current pipeline run.

- task: PublishBuildArtifacts@1
  displayName: 'Publish Cypress Screenshot Files'
  condition: failed()
  inputs:
    PathtoPublish: 'cypress/screenshots/'
    ArtifactName: 'screenshots'

Two notes about this:

  1. If you want to publish screenshots not only when the tests fail, then you have to remove the line condition: failed()
  2. The cypress/screenshots folder is only automatically created by Cypress if the test execution also creates screenshots. If no screenshot was created, then the folder does not exist and the above pipeline task would fail. Therefore I would also persist the empty screenshots folder in the repo by using a .gitkeep file.
Related