Hi,
I’d like my CI pipeline to run a test job for each test file in my repo. Every test file starts with the “Test_“ pattern. The number of test files is dynamic: if a PR adds a new test file to the repo I don’t want to manually specify that CI should run that test as well, so I created a job that finds files that match the pattern and generates a dynamic child pipeline with a job for each test. It’s important to have a job for each test because I want them to run in parallel. My setup works fine but the xml test results only show up in the “Tests“ tab of the child pipeline. Is there a way to pass this dynamic number of xml test results up to the parent pipeline, so that the “Tests“ tab of the parent pipeline is populated as well?
This is my .gitlab-ci.yml file:
stages:
- generate
- test
generate-test-jobs:
stage: generate
image: alpine:latest
script:
- apk add --no-cache bash
- ./generate_jobs.sh
artifacts:
paths:
- generated-jobs.yml
main-test-job:
stage: test
trigger:
include:
- artifact: generated-jobs.yml
job: generate-test-jobs
And this is my generate_jobs.sh script:
#!/bin/bash
# Create or clear the generated jobs file and define the template directly
cat << 'EOL' > generated-jobs.yml
.unit-test-template: &test_definition
stage: test
image: image-name
script:
- matlab -batch "runTests('${test_script}', '${output_file}')"
artifacts:
when: always
paths:
- junit_reports/
reports:
junit: ${output_file}
EOL
# Find all test files recursively
find . -type f -name 'Test_*.m' | while read -r test_file; do
# Extract the test name and directory
test_name=$(basename "$test_file" .m)
test_dir=$(dirname "$test_file")
output_file="junit_reports/${test_name}.xml"
# Append a job for each test file to the generated jobs file
cat << EOL >> generated-jobs.yml
${test_name}_job:
<<: *test_definition
variables:
test_script: "${test_dir}/${test_name}"
output_file: "${output_file}"
EOL
done