Skip to content

Instantly share code, notes, and snippets.

@ArturT
Last active April 13, 2021 18:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ArturT/90b7ec869e3827b580664beb086a8cd6 to your computer and use it in GitHub Desktop.
Save ArturT/90b7ec869e3827b580664beb086a8cd6 to your computer and use it in GitHub Desktop.
# bitbucket-pipelines.yml
# this is example using cypress/base docker image
image: cypress/base:10
options:
max-time: 30
# job definition for running E2E tests in parallel with KnapsackPro.com
e2e: &e2e
name: Run E2E tests with @knapsack-pro/cypress
caches:
- node
- cypress
script:
# run web application in the background
- npm run start:ci &
# env vars from https://support.atlassian.com/bitbucket-cloud/docs/variables-and-secrets/
- export KNAPSACK_PRO_CI_NODE_BUILD_ID=$BITBUCKET_BUILD_NUMBER
- export KNAPSACK_PRO_COMMIT_HASH=$BITBUCKET_COMMIT
- export KNAPSACK_PRO_BRANCH=$BITBUCKET_BRANCH
- export KNAPSACK_PRO_CI_NODE_TOTAL=$BITBUCKET_PARALLEL_STEP
- export KNAPSACK_PRO_CI_NODE_INDEX=$BITBUCKET_PARALLEL_STEP_COUNT
# https://github.com/KnapsackPro/knapsack-pro-cypress#configuration-steps
- export KNAPSACK_PRO_FIXED_QUEUE_SPLIT=true
- $(npm bin)/knapsack-pro-cypress
artifacts:
# store any generated images and videos as artifacts
- cypress/screenshots/**
- cypress/videos/**
pipelines:
default:
- step:
name: Install dependencies
caches:
- npm
- cypress
- node
script:
- npm ci
- parallel:
# run N steps in parallel
- step:
<<: *e2e
- step:
<<: *e2e
- step:
<<: *e2e
definitions:
caches:
npm: $HOME/.npm
cypress: $HOME/.cache/Cypress
# this is example using node docker image. The cypress docker image is used on the parallel step level.
image: node:14.15.5
options:
max-time: 30
e2e: &e2e
name: Run parallel tests with @knapsack-pro/cypress
caches:
- npm
- cypress
# cypress docker image
image: cypress/included:6.5.0
# env vars from https://support.atlassian.com/bitbucket-cloud/docs/variables-and-secrets/
script:
- npm install
- npm run start
# env vars from https://support.atlassian.com/bitbucket-cloud/docs/variables-and-secrets/
- export KNAPSACK_PRO_COMMIT_HASH=$BITBUCKET_COMMIT
- export KNAPSACK_PRO_BRANCH=$BITBUCKET_BRANCH
- export KNAPSACK_PRO_CI_NODE_BUILD_ID=$BITBUCKET_BUILD_NUMBER
- export KNAPSACK_PRO_CI_NODE_TOTAL=$BITBUCKET_PARALLEL_STEP
- export KNAPSACK_PRO_CI_NODE_INDEX=$BITBUCKET_PARALLEL_STEP_COUNT
# https://github.com/KnapsackPro/knapsack-pro-cypress#configuration-steps
- export KNAPSACK_PRO_FIXED_QUEUE_SPLIT=true
- $(npm bin)/knapsack-pro-cypress
artifacts:
- cypress/reports/**
- cypress/videos/**
pipelines:
default:
# How to run parallel tests https://support.atlassian.com/bitbucket-cloud/docs/set-up-or-run-parallel-steps/
# You should add KNAPSACK_PRO_TEST_SUITE_TOKEN_CYPRESS as secure variable https://support.atlassian.com/bitbucket-cloud/docs/variables-and-secrets/
# to not expose Knapsack Pro API token in this config file.
- parallel:
# run N steps in parallel
- step:
<<: *e2e
- step:
<<: *e2e
- step:
<<: *e2e
definitions:
caches:
npm: $HOME/.npm
cypress: $HOME/.cache/Cypress
@ArturT
Copy link
Author

ArturT commented Apr 12, 2021

@hvaandres

npm run start command is specific to a project. Maybe you need to start web application in your project with a different command like npm run start:ci. You can check that in your project package.json.

Regarding error

Response error body: { errors: [ { node_total: [ 'must be greater than or equal to 2' ] } ] }

You need to double-check if env var has value BITBUCKET_PARALLEL_STEP and BITBUCKET_PARALLEL_STEP_COUNT. They are available in parallel steps only.

to display value run:

echo $BITBUCKET_PARALLEL_STEP 
echo $BITBUCKET_PARALLEL_STEP_COUNT

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment