Last active
April 13, 2021 18:40
-
-
Save ArturT/90b7ec869e3827b580664beb086a8cd6 to your computer and use it in GitHub Desktop.
BitBucket Pipeline parallel tests for Cypress with @knapsack-pro/cypress https://knapsackpro.com/?utm_source=github&utm_medium=gist&utm_campaign=gist-bitbucket-pipeline-knapsack-pro-cypress
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This is the error message that I'm getting:
$(npm bin)/knapsack-pro-cypress
npm ERR! missing script: start:ci
npm ERR!
npm ERR! Did you mean this?
npm ERR! start
npm ERR! A complete log of this run can be found in:
npm ERR! /root/.npm/_logs/2021-04-12T18_36_37_518Z-debug.log
2021-04-12T18:36:38.223Z [@knapsack-pro/core] info: POST https://api.knapsackpro.com/v1/queues/queue
2021-04-12T18:36:38.560Z [@knapsack-pro/core] error: 422 Unprocessable Entity
Request ID:
ba94ce33-7ae0-4341-91b7-dee1ebc279d9
Response error body:
{ errors: [ { node_total: [ 'must be greater than or equal to 2' ] } ] }
(node:70) UnhandledPromiseRejectionWarning: Error: Knapsack Pro API returned an error. See the above logs.
at /opt/atlassian/pipelines/agent/build/node_modules/@knapsack-pro/core/lib/knapsack-pro-core.js:46:23
at process._tickCallback (internal/process/next_tick.js:68:7)
(node:70) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 4)
(node:70) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
If I run the second option, I get the following error message:
+ npm run start
> [email protected] start
> my-server -p 3030
sh: 1: my-server: not found
npm ERR! code 127
npm ERR! path /opt/atlassian/pipelines/agent/build
npm ERR! command failed
npm ERR! command sh -c my-server -p 3030
npm ERR! A complete log of this run can be found in:
npm ERR! /root/.npm/_logs/2021-04-12T19_16_04_384Z-debug.log
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
Learn more about how Queue Mode in Knapsack Pro can distribute tests to get the shortest CI build time:
https://docs.knapsackpro.com/2020/how-to-speed-up-ruby-and-javascript-tests-with-ci-parallelisation