we are using Cypress and Bitbucket pipelines. We have several development environments and I want to change the baseurl dynamically depending on which branch I select via Bitbucket pipelines.
the script for running the Cypress commands in Bitbucket pipelines looks like this:
script:
- ./hybris-url-mapping.sh $CYPRESS_BASE_URL
- cd /working
- npx cypress run --env baseUrl=$CYPRESS_BASE_URL
the script (./hybris-url-mapping.sh) which should change the URL based on the selected branch looks like this
if [[ $BITBUCKET_BRANCH == 'develop' ]]; then CYPRESS_BASE_URL="develop_url" ; fi
if [[ $BITBUCKET_BRANCH == 'staging' ]]; then CYPRESS_BASE_URL="staging_url" ; fi
if [[ $BITBUCKET_BRANCH == 'staging2' ]]; then CYPRESS_BASE_URL="staging2_url" ; fi
if [[ $BITBUCKET_BRANCH == 'release' ]]; then CYPRESS_BASE_URL="prod_url" ; fi
echo $CYPRESS_BASE_URL
now we come to the problem. Unfortunately it does not work. At least in echo $CYPRESS_BASE_URL the correct URL is returned based on the branch but it is not set as baseUrl in the commandline npx cypress run --env baseUrl=$CYPRESS_BASE_URL. There the url in the cypress.json is always used:
{
"baseUrl": "local_url"
}
i have tried npx cypress run --env baseUrl=$CYPRESS_BASE_URL and
npx cypress run --config baseUrl=$CYPRESS_BASE_URL but neither works.
What am I doing wrong?