How to configure pipeline yaml to run in parallel
Asked by Vincent Jong:

We have our pipelines to run our webdriverio tests in a docker container. It works when run serially but after configuring our tests in general through the wdio conf to run tests single or multi-threaded, multi-threaded runs only works when running the tests without docker, locally only. Bitbucket pipeline runs look like threads get created but then hang until finally exiting on failure. What do I need to add/modify/remove in the pipeline yaml to run successfully? If there's anything else needed, let me know and thanks for any help and consideration!

Command structure:

```
STAGE=stg SOURCE_TEST_DIR=$SOURCE_TEST_DIR THREADED=true npm run tests:e2e:docker:ci
```

envConfig.ts:

```
export const Threads = process.env.THREADED === "true" ? 5 : 1; // if THREADED, run 5 threads, else default 1.
```

wdio docker conf:

```
import {Threads} from "./envConfig";

buildConfig.hostname = 'chromedriver'
buildConfig.port = 4444
// this is not really headless, but required to pass a check on login.
// it would seem that mfa-detect-browser-capabilities detects the hardware requirements
// for multifactor authentication. in docker environment the test runs in a non-headless chrome
// but behaves differently due to biometrics capability on docker container vs your own macbook
buildConfig.headless = true

buildConfig.capabilities = [{

 // maxInstances can get overwritten per capability. So if you have an in-house Selenium
 // grid with only 5 firefox instances available you can make sure that not more than
 // 5 instances get started at a time.
 maxInstances: Threads,
...
```

bitbucket-pipelines.yml:

```
image: tendocicd/pipeline_builder:latest

definitions:
 scripts:
 - script: &RepoPrivateKey
 git config --global url."git@bitbucket.org:tendosystems".insteadOf "https://bitbucket.org/tendosystems" &&
 echo "export GOPRIVATE=bitbucket.org/tendosystems/*" >> ~/.bashrc
 steps:
 - step: &testEndToEndInStg
 artifacts:
 - node_modules/**
 - reports/**
 name: End To End Tests in Docker Container - ChromeDriver
 services:
 - docker
 script:
 - echo ${AWS_DEFAULT_REGION}
 - source docker-setup.sh
 - echo SOURCE_TEST_DIR $SOURCE_TEST_DIR
 - npm install
 - npm run build
 - mkdir reports;chmod -R 777 reports
 - STAGE=stg SOURCE_TEST_DIR=$SOURCE_TEST_DIR THREADED=true npm run tests:e2e:docker:ci -- --cucumberOpts.tagExpression="@bats and not @skip"
 - npm run report:generate

pipelines:
 pull-requests:
 '**':
 - step: *testEndToEndInStg
 custom:
 e2e-stg:
 - step: *testEndToEndInStg
```


Answers:
author: Mark C
body: Hi [@Vincent Jong](/t5/user/viewprofilepage/user-id/5225653),

Welcome to the community.

Would you be able to share any failure error message you're getting when the build failed on Bitbucket Cloud Pipelines?

Also, for hanging build, you can add the below monitoring commands to observe which process is consuming more memory. This can help to narrow down the issue.

```
- while true; do echo "Memory usage in bytes:" && cat /sys/fs/cgroup/memory/memory.memsw.usage_in_bytes; sleep 2; done & 2- while true; do date && ps aux && echo "" && sleep 2; done &
```

You can also check this link for more information on [troubleshooting Bitbucket Cloud Pipelines](https://confluence.atlassian.com/bbkb/troubleshooting-bitbucket-pipelines-1141505226.html).

Regards,  
Mark C

comments: author: Vincent Jong
body: Not sure which command it couldn't find...

```
1?+ while true; do echo "Memory usage in bytes:" && cat /sys/fs/cgroup/memory/memory.memsw.usage_in_bytes; sleep 2; done & 2
2?Memory usage in bytes:
3?bash: 2: command not found
4?849416192
5
6
```

```
- step: &testEndToEndInStg
  artifacts:
    - node_modules/**
    - reports/**
  name: End To End Tests in Docker Container - ChromeDriver
  services:
    - docker
  script:
    - echo ${AWS_DEFAULT_REGION}
    - source docker-setup.sh
    - echo SOURCE_TEST_DIR $SOURCE_TEST_DIR
    - npm install
    - npm run build
    - mkdir reports;chmod -R 777 reports
    - while true; do echo "Memory usage in bytes:" && cat /sys/fs/cgroup/memory/memory.memsw.usage_in_bytes; sleep 2; done & 2
    - while true; do date && ps aux && echo "" && sleep 2; done &
    - STAGE=stg SOURCE_TEST_DIR=$SOURCE_TEST_DIR THREADED=true npm run tests:e2e:bats:docker
    - npm run report:generate
```


author: Vincent Jong
body: Interesting, now it's been failing fast. It gives me the error below. Special to trying to run multiple threads through docker? The single threaded pipeline using docker doesn't see this...
> Couldn't connect to Docker daemon at <http://localhost:2375> - is it running?


author: Mark C
body: Hi @\[deleted\]  

It seems failing locally as well.  

With regards to running multi-threaded commands, please be informed that [Bitbucket Pipelines runs in a shared infrastructure environment](https://community.atlassian.com/t5/Bitbucket-questions/Number-of-CPUs-available-in-BB-pipelines/qaq-p/972594) which means your step container CPU resources may vary from time to time.

I'd suggest try reducing the number of threads you'd like to run or consider using [Bitbucket Cloud Pipelines runners](https://support.atlassian.com/bitbucket-cloud/docs/runners/) which will allow you to run builds on your self-hosted machine.  

Regards,  
Mark C


Tags: bitbucket-cloud

cloud

parallel