Moves the Jira writeback script to a more appropriate location. Updates the Azure Pipelines configuration to reflect the new path.
198 lines
No EOL
7.5 KiB
YAML
198 lines
No EOL
7.5 KiB
YAML
schedules:
|
|
- cron: 0 9 * * MON-FRI
|
|
always: true
|
|
displayName: Daily Test Automation Run for FMG-NextGen
|
|
branches:
|
|
include:
|
|
- main
|
|
|
|
pool: 'AmazonLinuxPool'
|
|
|
|
variables:
|
|
# - group: Digital-Infrastructure
|
|
# - group: FMG-BuildBranches
|
|
- name: dockerImageName
|
|
value: 'playwright-tests'
|
|
- name: imageTag
|
|
value: '$(Build.BuildId)'
|
|
- name: totalShards
|
|
value: 4
|
|
|
|
stages:
|
|
- stage: TestPr
|
|
displayName: Run Playwright Test
|
|
jobs:
|
|
- job: playwright_tests
|
|
continueOnError: true
|
|
strategy:
|
|
matrix:
|
|
shard1:
|
|
shardNumber: 1
|
|
shard2:
|
|
shardNumber: 2
|
|
shard3:
|
|
shardNumber: 3
|
|
shard4:
|
|
shardNumber: 4
|
|
|
|
steps:
|
|
- task: Docker@2
|
|
displayName: 'Build Docker Image'
|
|
inputs:
|
|
command: build
|
|
dockerfile: Dockerfile.playwright
|
|
repository: $(dockerImageName)
|
|
tags: $(imageTag)
|
|
arguments: '--no-cache --pull'
|
|
|
|
- script: |
|
|
# Create container and run tests
|
|
container_id=$(docker create \
|
|
--ipc=host \
|
|
-e CCIS_API_AUTH=$(CCIS_API_AUTH) \
|
|
-e BASE_URL=$(BASE_URL) \
|
|
-e CCIS_API_URL=$(CCIS_API_URL) \
|
|
-e ADMIN_SERVICE_API_URL=$(ADMIN_SERVICE_API_URL) \
|
|
-e SHARD=$(shardNumber) \
|
|
-e CI=true \
|
|
-e NODE_ENV=$(NODE_ENV) \
|
|
$(dockerImageName):$(imageTag) \
|
|
npm run test:playwright -- --shard=$(shardNumber)/$(totalShards) --reporter=list,blob --grep '@(Alert|CASH)')
|
|
|
|
# Start container and stream logs
|
|
echo "Starting tests for shard $(shardNumber)..."
|
|
docker start -a $container_id
|
|
|
|
# Create directory for test results
|
|
echo "Creating test results directory..."
|
|
mkdir -p $(System.DefaultWorkingDirectory)/blob-reports/shard-$(shardNumber)
|
|
|
|
# Copy test results from container
|
|
echo "Copying test results..."
|
|
docker cp $container_id:/app/blob-report/. $(System.DefaultWorkingDirectory)/blob-reports/shard-$(shardNumber)/
|
|
|
|
# Remove container
|
|
echo "Cleaning up container..."
|
|
docker rm $container_id
|
|
|
|
# Check if tests failed
|
|
if [ $? -ne 0 ]; then
|
|
echo "Tests failed in shard $(shardNumber) or tests don't exist for this shard number!"
|
|
exit 0 # Suppress error. It will be visible in report.
|
|
fi
|
|
displayName: 'Run Playwright Tests - Shard $(shardNumber)'
|
|
|
|
- task: PublishPipelineArtifact@1
|
|
displayName: 'Publish Test Reports - Shard $(shardNumber)'
|
|
condition: always()
|
|
inputs:
|
|
targetPath: '$(System.DefaultWorkingDirectory)/blob-reports/shard-$(shardNumber)'
|
|
artifact: 'playwright-report-shard-$(shardNumber)'
|
|
publishLocation: 'pipeline'
|
|
|
|
- script: |
|
|
docker rmi $(dockerImageName):$(imageTag) -f
|
|
displayName: 'Cleanup Docker Image'
|
|
condition: always()
|
|
|
|
- job: download_and_merge_reports
|
|
dependsOn: playwright_tests
|
|
timeoutInMinutes: 8
|
|
cancelTimeoutInMinutes: 10
|
|
steps:
|
|
- task: DownloadPipelineArtifact@2
|
|
inputs:
|
|
targetPath: '$(System.DefaultWorkingDirectory)/playwright-reports'
|
|
- task: Docker@2
|
|
displayName: 'Build Docker Image'
|
|
inputs:
|
|
command: build
|
|
dockerfile: Dockerfile.playwright
|
|
repository: $(dockerImageName)
|
|
tags: $(imageTag)
|
|
arguments: '--no-cache --pull'
|
|
- bash: |
|
|
# branch_name=$(Build.SourceBranch)
|
|
# TODO: Replace hardcoded Jira card. Better to search the active sprint for regression card and create one if not found.
|
|
jira_card_number="CASH-425"
|
|
|
|
# Get current day of week and numeric date for report name
|
|
current_day=$(date +%A)
|
|
numeric_date=$(date +%m-%d-%Y)
|
|
report_name="ortoni-report-${NODE_ENV}-${current_day}-${numeric_date}.html"
|
|
|
|
# Create container for jira writeback
|
|
container_id=$(docker create \
|
|
--ipc=host \
|
|
-e JIRA_SERVER=$(JIRA_SERVER) \
|
|
-e JIRA_USERNAME=$(JIRA_USERNAME) \
|
|
-e JIRA_API_KEY=$(JIRA_API_KEY) \
|
|
-e jira_card_number="$jira_card_number" \
|
|
-e REPORT_NAME="$report_name" \
|
|
-e CURRENT_DAY="$current_day" \
|
|
-e NUMERIC_DATE="$numeric_date" \
|
|
$(dockerImageName):$(imageTag) \
|
|
bash -c "chmod +x devops/scripts/jira_writeback.sh
|
|
echo \"Moving Playwright reports out of subfolders...\"
|
|
find ./playwright-reports/ -mindepth 2 -type f -exec mv {} ./playwright-reports/ \;
|
|
echo \"Merging reports...\"
|
|
PLAYWRIGHT_JUNIT_OUTPUT_DIR='/app/test-results' PLAYWRIGHT_JUNIT_OUTPUT_NAME='junit_results.xml' npx playwright merge-reports --reporter=ortoni-report,junit ./playwright-reports
|
|
echo \"Contents of ortoni-report:\" && ls ./ortoni-report
|
|
echo 'Current dir: ' && pwd
|
|
echo 'Contents of current dir: ' && ls
|
|
echo 'Contents of /app/test-results' && ls /app/test-results
|
|
|
|
# Rename the report file to include the day and date
|
|
if [ -f /app/ortoni-report/ortoni-report.html ]; then
|
|
mv /app/ortoni-report/ortoni-report.html /app/ortoni-report/\${REPORT_NAME}
|
|
echo \"Renamed report to \${REPORT_NAME}\"
|
|
else
|
|
echo \"ortoni-report.html not found!\"
|
|
fi
|
|
|
|
echo \"Writing report to Jira card '$jira_card_number'...\"
|
|
/app/devops/scripts/jira_writeback.sh add_comment \"$jira_card_number\" /app/ortoni-report/\${REPORT_NAME} \"AUTOMATED TEST RUN: $(date) - \${CURRENT_DAY} (\${NUMERIC_DATE})\" ")
|
|
|
|
# Start container and stream logs
|
|
echo "Starting merge"
|
|
docker start -a $container_id
|
|
|
|
# Create directory for test results
|
|
echo "Creating test results directory..."
|
|
mkdir -p $(System.DefaultWorkingDirectory)/ortoni-report
|
|
mkdir -p $(System.DefaultWorkingDirectory)/test-results
|
|
|
|
# Copy test results from container
|
|
echo "Copying test results..."
|
|
docker cp $container_id:/app/ortoni-report/. $(System.DefaultWorkingDirectory)/ortoni-report
|
|
docker cp $container_id:/app/test-results/junit_results.xml $(System.DefaultWorkingDirectory)/test-results
|
|
|
|
# Remove container
|
|
echo "Cleaning up container..."
|
|
docker rm $container_id
|
|
env:
|
|
JIRA_API_KEY: $(JIRA_API_KEY)
|
|
displayName: merge_and_publish_results_to_jira
|
|
|
|
- task: PublishTestResults@2
|
|
displayName: 'Publish test results'
|
|
inputs:
|
|
searchFolder: 'test-results'
|
|
testResultsFormat: 'JUnit'
|
|
testResultsFiles: 'junit_results.xml'
|
|
mergeTestResults: true
|
|
failTaskOnFailedTests: false
|
|
testRunTitle: 'Playwright Tests'
|
|
condition: succeededOrFailed()
|
|
|
|
- task: PublishPipelineArtifact@1
|
|
displayName: 'Publish Merged Report'
|
|
condition: always()
|
|
inputs:
|
|
targetPath: '$(System.DefaultWorkingDirectory)/ortoni-report'
|
|
artifact: 'playwright-merged-report'
|
|
publishLocation: 'pipeline'
|
|
- script: |
|
|
docker rmi $(dockerImageName):$(imageTag) -f
|
|
displayName: 'Cleanup Docker Image'
|
|
condition: always() |