7

I run e2e tests on CI environment, but I cannot see the artifacts in pipelines.

bitbucket-pipelines.yml:

image: cypress/base:10
options: max-time: 20
pipelines: 
  default: 
    -step: 
        script: 
            - npm install 
            -npm run test 
        artifacts: 
            -/opt/atlassian/pipelines/agent/build/cypress/screenshots/* 
            -screenshots/*.png

enter image description here

enter image description here

Maybe I typed in the wrong way path, but I am not sure.

Does anyone have any ideas what I am doing wrong?

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
enjoyit
  • 111
  • 2
  • 9

3 Answers3

7

I don't think it's documented anywhere but artifacts only accepts a relative directory from $BITBUCKET_CLONE_DIR. When I run my pipeline it says: Cloning into '/opt/atlassian/pipelines/agent/build'..., so I think artifacts is relative to that path. My guess is that if you change it to something like this, it will work:

image: cypress/base:10
options: max-time: 20
pipelines: 
  default: 
    -step: 
        script: 
            - npm install 
            -npm run test 
        artifacts: 
            - cypress/screenshots/*.png

Edit

From your comment I now understand what the real problem is: BitBucket pipelines are configured to stop at any non-zero exit code. That means that the pipeline execution is stopped when cypress fails the tests. Because artifacts are stored after the last step of the pipeline, you won't have any artifacts.

To work around this behavior you have to make sure the pipeline doesn't stop until the images are saved. One way to do this is to prefix the npm run test part with set +e (for more details about this solution, look at this answer here: https://community.atlassian.com/t5/Bitbucket-questions/Pipeline-script-continue-even-if-a-script-fails/qaq-p/79469). This will prevent the pipeline from stopping, but also makes sure that your pipeline always finishes! Which of course is not what you want. Therefore I recommend that you run cypress tests separately and create a second step in your pipeline to check the output of cypress. Something like this:

# package.json

...
"scripts": {
  "test": "<your test command>",
  "testcypress": "cypress run ..."
...

# bitbucket-pipelines.yml

image: cypress/base:10
options: max-time: 20
pipelines: 
  default: 
    - step:
        name: Run tests
        script:
            - npm install
            - npm run test
            - set +e npm run testcypress
        artifacts: 
            - cypress/screenshots/*.png
    -step:
        name: Evaluate Cypress
        script:
            - chmod +x check_cypress_output.sh
            - ./check_cypress_output.sh

# check_cypress_output.sh

# Check if the directory exists
if [ -d "./usertest" ]; then

    # If it does, check if it's empty
    if [ -z "$(ls -A ./usertest)" ]; then

        # Return the "all good" signal to BitBucket if the directory is empty
        exit 0
    else

        # Return a fault code to BitBucket if there are any images in the directory
        exit 1
    fi

# Return the "all good" signal to BitBucket
else
    exit 0
fi

This script will check if cypress created any artifacts, and will fail the pipeline if it did. I'm not sure this is exactly what you need but it's probably a step in the direction.

Gijs Wobben
  • 1,974
  • 1
  • 10
  • 13
  • Hi Gijs Wobben, thank you for your message. Unfortunately, it still doesn't work. I already tried for many different ways solve it, but I have no any idea why it is not working – enjoyit Dec 03 '18 at 13:18
  • I'm not sure if you did this already, but you might try to add some ls commands in your pipeline definition to see what's going on inside the container: - ls -la /opt/atlassian/pipelines/agent/build - ls -la /opt/atlassian/pipelines/agent/build/cypress - ls -la /opt/atlassian/pipelines/agent/build/cypress/screenshots ... – Gijs Wobben Dec 04 '18 at 14:09
  • I tried this, but still nothing happened. What I got (in every failed pipeline - tests) is that: npm ERR! Code ELIFECYCLE npm ERR! errno 3 npm ERR! @test: 'cypress run' npm ERR! Exit status 3 npm ERR! npm ERR! Failed at the @ test script. npm ERR! This is probably not a problem with npm. There is likely additional logging output above. npm ERR! A complete log of this run can be found in: npm ERR! /root/.npm/_logs/2018-12-05T11_19_56_845Z-debug.log What I want to see is screenshots when something went wrong with the tests (When It was) – enjoyit Dec 05 '18 at 12:25
  • A response to this comment was too long, so I updated my answer ;) – Gijs Wobben Dec 06 '18 at 13:39
  • Total agree @GijsWobben ! You hit the nail! On the other hand, I could see that the files can be referenced from the current directory, unlike the folders, where they must be indicated with the path relative to the $BITBUCKET_CLONE_DIR constant, as you said very well. – Ramon Costa Apr 05 '23 at 11:55
0

Recursive search (/**) worked for me with Cypress 3.1.0, due to additional folder inside videos and screenshots

# [...]
pipelines: 
  default: 
    - step:
      name: Run tests
      # [...]
      artifacts:
        - cypress/videos/** # Double star provides recursive search.
        - cypress/screenshots/** 
smoq
  • 130
  • 2
  • 6
0

this is my working solution 'cypress:pipeline' is the custom pipeline in my bitbucket config file to run cypress. please try cypress/screenshots/**/*.png in artifact section

"cypress:pipeline": "cypress run --env user=${E2E_USER_EMAIL},pass=${E2E_USER_PASSWORD} --browser chrome --spec cypress/integration/src/**/*.spec.ts"

pipelines:
  custom:
    healthCheck:
      - step:
          name: Integration and E2E Test
          script:
            - npm install
            - npm run cypress:pipeline
          artifacts:
            # store any generated images as artifacts
            - cypress/screenshots/**/*.png
Community
  • 1
  • 1