I have a config file which contains a REST API testing image using Cypress and MongoDB which is required as a backend via an env var MONGODB_URI.
If I run cypress npm test command locally, it works as expected. On Circle CI it fails, and I think the API image is not seeing the Environment Variable MONGODB_URI as it can’t find the database, thereby not spinning up the API, and Cypress is not able to run the tests.
I’ve attached my config.yaml any help is appreciated and I am happy to pay for support as I need to get this infra up and running…
This is my config.yml
Any guidance is much appreciated!
version: 2.1
orbs:
cypress: cypress-io/cypress@1
# using service containers on CircleCI
# https://github.com/cypress-io/circleci-orb/blob/master/docs/recipes.md#service-containers
# https://circleci.com/docs/2.0/databases/
executors:
with-mongo:
docker:
- image: cypress/base:14.16.0
environment:
MONGODB_URI: mongodb://$MONGO_INITDB_ROOT_USERNAME:$MONGO_INITDB_ROOT_PASSWORD@localhost:27017/?authSource=admin
- image: mongo:4.4.5
environment:
MONGO_INITDB_ROOT_USERNAME: $MONGO_INITDB_ROOT_USERNAME
MONGO_INITDB_ROOT_PASSWORD: $MONGO_INITDB_ROOT_PASSWORD
workflows:
build:
jobs:
- cypress/run:
executor: with-mongo
start: npm test
# no need to save the workspace after this job
no-workspace: true
Here is the image of the build error
I have configured the environment variables required by my API on the project as well
Name Value
MONGODB_URI xxxxdzzz
MONGO_INITDB_DATABASE xxxxzzxx
MONGO_INITDB_ROOT_PASSWORD xxxxrd0x
MONGO_INITDB_ROOT_USERNAME xxxxxx
NODE_ENV xxxxzzzx