I am attempting to produce test results, for Flutter Unit tests, using junit, via a GitLab pipeline stage, however I keep getting error:
no matching files. Ensure that the artifact path is relative to the working directory
I am not convinced that junit is producing a test report, however I am unsure how to confirm this. Coverage is also covered.
Yaml files are as follows:
.gitlab-ci.yml
webapp:unit-test:
extends: .webapp:unit-test
stage: test
allow_failure: true
only:
changes:
<removed>
flutterapp.gitlab-ci.yml
.webapp:unit-test: &webapp_unit-test
image: $CI_REGISTRY_IMAGE/flutter:$CI_COMMIT_REF_NAME
cache:
paths:
script:
- cd $APP_DIR
- flutter pub upgrade
- flutter pub global activate junitreport
- export PATH="$PATH":"$HOME/.pub-cache/bin"
- flutter test --coverage --machine | tojunit --output report.xml
- lcov --list coverage/lcov.info
- genhtml coverage/lcov.info --output=coverage
coverage: '/\s*lines\.*:\s*([\d\.]+%)/'
artifacts:
reports:
junit:
- $UNIT_TESTS_PATH/report.xml
paths:
- $VARIABLES_FILE
- $COVERAGE_RESULTS_PATH/coverage
- $UNIT_TESTS_PATH/report.xml
when: always
allow_failure: true
How can I confirm junit is producing a report, and if so, how can I find the correct path?
The error message mentions that you need to:
Ensure that the artifact path is relative to the working directory
let's break this down ...
paths
: This keyword is used just to determine which files to be included in the job artifacts.
working directory
: Think of your working directory as your repository (they are not the same but they are very similar to each other). For the artifacts paths, make sure that you are using a relative paths (paths similar to the ones in your repository)
As mentioned in Gitlab docs:
The paths keyword determines which files to add to the job artifacts. All paths to files and directories are relative to the repository where the job was created.
As mentioned above, the path must be relative. In other words, it should be a child of the project directory $CI_PROJECT_DIR/
.
For example, you may change to the output path by adding the predefined variable $CI_PROJECT_DIR (or use any other path in the working directory):
- flutter test --coverage --machine | tojunit --output $CI_PROJECT_DIR/report.xml
- lcov --list coverage/lcov.info
- genhtml coverage/lcov.info --output=$CI_PROJECT_DIR/coverage
Make sure that all the files' paths under paths
keyword are relative paths (children of the $CI_PROJECT_DIR/ directory):
paths:
- $VARIABLES_FILE
- $CI_PROJECT_DIR/coverage
- $CI_PROJECT_DIR/report.xml
note that the $VARIABLES_FILE should be relative too.