Loads environment variables in Docker containers

Ensures environment variables defined in the env file are loaded
into the Docker containers used for Playwright tests. This is
achieved by sourcing the env file within the `docker create` command.

Removes the unnecessary CI=true environment variable setting.
This commit is contained in:
maguire-arman 2025-07-15 11:29:49 -04:00
parent 1f96ce255b
commit 07efa18134
2 changed files with 11 additions and 6 deletions

View file

@ -1,5 +1,3 @@
FROM node:20
FROM mcr.microsoft.com/playwright:v1.48.0-noble
# Set the working directory in the container

View file

@ -162,7 +162,6 @@ jobs:
TOTAL_SHARDS=${{ parameters.totalShards }}
container_id=$(docker create \
--ipc=host \
--env CI=true \
--env-file "${{ parameters.envFileName }}" \
${{ parameters.dockerImageName }}:${{ parameters.imageTag }} \
npx concurrently -k -n 'server,playwright' \
@ -177,12 +176,17 @@ jobs:
export SERVE_PATH="${{ parameters.npmServePath }}"
export SHARD_NUMBER=$(shardNumber)
export TOTAL_SHARDS=${{ parameters.totalShards }}
export ENV_FILE="${{ parameters.envFileName }}"
container_id=$(docker create \
--ipc=host \
--env CI=true \
--env-file "${{ parameters.envFileName }}" \
${{ parameters.dockerImageName }}:${{ parameters.imageTag }} \
bash -c "PLAYWRIGHT_BLOB_OUTPUT_DIR='/app/blob-report' npx --prefix $PLAYWRIGHT_PATH playwright test $PLAYWRIGHT_PATH --config=$PLAYWRIGHT_PATH/playwright.config.ts --shard=$SHARD_NUMBER/$TOTAL_SHARDS --reporter=list,blob $FILTER" \
bash -c "
set -a
source $ENV_FILE
set +a
PLAYWRIGHT_BLOB_OUTPUT_DIR='/app/blob-report' npx --prefix $PLAYWRIGHT_PATH playwright test $PLAYWRIGHT_PATH --config=$PLAYWRIGHT_PATH/playwright.config.ts --shard=$SHARD_NUMBER/$TOTAL_SHARDS --reporter=list,blob $FILTER
" \
)
fi
# Start container and stream logs
@ -250,12 +254,15 @@ jobs:
export JIRA_CARD_NUMBER="$JIRA_CARD_NUMBER"
export ENV_FILE="${{ parameters.envFileName }}"
container_id=$(docker create \
--ipc=host \
--env CI=true \
--env-file "${{ parameters.envFileName }}" \
${{ parameters.dockerImageName }}:${{ parameters.imageTag }} \
bash -c "
set -a
source $ENV_FILE
set +a
echo 'Moving Playwright reports out of subfolders...'
find ./playwright-reports/ -mindepth 2 -type f -exec mv {} ./playwright-reports/ \;
echo 'Value of JIRA_CARD_NUMBER in bash -c command: $JIRA_CARD_NUMBER'