Inconsistent behaviour on `paths` when used with `expose_as` keyword
Summary
When used with expose_as
, artifacts:paths
require trailing / on directories. Without the trailing /, the directories will not be taken into account into the exposed artifacts MR widget, even though the directories are correctly included in the artifact. The documentation in https://docs.gitlab.com/ee/ci/pipelines/job_artifacts.html#expose-job-artifacts-in-the-merge-request-ui should explicitly mention the need for /.
Using the instructions here, https://docs.gitlab.com/ee/ci/pipelines/job_artifacts.html#expose-job-artifacts-in-the-merge-request-ui, I am trying to set the public
directory as a downloadable artifact, with the following diff:
diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 3eb1e40..a915967 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -57,16 +57,23 @@ run_tests:
script:
- pip install -e '.[dev]'
- pip freeze # print out installed versions for debugging
- - coverage run --source=src -m pytest -v --junitxml=report.xml tests
+ - coverage run --branch --source=src -m pytest -v --junitxml=report.xml
- coverage report
- coverage xml
+ - coverage html
+ - mkdir -p public/
+ - cp -r htmlcov public/
+ coverage: '/(?i)total.*? (100(?:\.0+)?\%|[1-9]?\d(?:\.\d+)?\%)$/'
artifacts:
+ expose_as: tests
when: always
reports:
junit: report.xml
coverage_report:
coverage_format: cobertura
path: coverage.xml
+ paths:
+ - public
run_benchmarks:
stage: test
However, that results in failure (0 exposed artifact):
Trying to "mix and match" the instructions on the aforementioned tutorial, I get:
diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index fab29863435abc834adc210291570c3df2a2a218..3c646e0a99ad3a59029825eb7f372bcc07112351 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -19,7 +19,7 @@ include:
- template: Security/SAST.gitlab-ci.yml
- project: 'masked/ci-template'
ref: $CI_TEMPLATE_TAG_REF
- file: 'base-templates.yaml'
+ file: 'utils.yaml'
semgrep-sast:
cache: { }
@@ -44,6 +44,20 @@ build-te-image:
- docker push "$TE_TAG"
interruptible: true
+test-file:
+ stage: test
+ script: [ "echo 'test' > file.txt" ]
+ artifacts:
+ expose_as: 'artifact 1'
+ paths: [ 'file.txt' ]
+
+test-dir:
+ stage: test
+ script: [ "mkdir test && echo 'test' > test/file.txt" ]
+ artifacts:
+ expose_as: 'artifact 2'
+ paths: [ 'test/' ]
+
run_tests:
stage: test
image: $CI_REGISTRY_IMAGE/te:$CI_COMMIT_REF_SLUG
@@ -56,6 +70,7 @@ run_tests:
- coverage report
- coverage xml
- coverage html
+ - echo 'test' > file.txt
coverage: '/(?i)total.*? (100(?:\.0+)?\%|[1-9]?\d(?:\.\d+)?\%)$/'
artifacts:
expose_as: tests
@@ -66,7 +81,8 @@ run_tests:
coverage_format: cobertura
path: coverage.xml
paths:
- - public
+ - htmlcov # generated by `coverage html`
+ - file.txt
run_benchmarks:
stage: test
with tests
being only the text file included in the exposed artifacts.
The other two examples "work as advertized"
Steps to reproduce
Example Project
What is the current bug behavior?
What is the expected correct behavior?
expose_as
works a little bit like:
tar czf "${expose_as}" "${paths[@]}"
, and adding a URL to the resulting file.
Hopefully, textual artifacts (test.txt
) can be rendered in-browser, instead of "forcefully" downloaded.
Relevant logs and/or screenshots
Output of checks
This bug happens on GitLab.com
Results of GitLab environment info
Expand for output related to GitLab environment info
(For installations with omnibus-gitlab package run and paste the output of: `sudo gitlab-rake gitlab:env:info`) (For installations from source run and paste the output of: `sudo -u git -H bundle exec rake gitlab:env:info RAILS_ENV=production`)
Results of GitLab application Check
Expand for output related to the GitLab application check
(For installations with omnibus-gitlab package run and paste the output of:
sudo gitlab-rake gitlab:check SANITIZE=true
)(For installations from source run and paste the output of:
sudo -u git -H bundle exec rake gitlab:check RAILS_ENV=production SANITIZE=true
)(we will only investigate if the tests are passing)
Possible fixes
Sample MRs:
alberts-gitlab/gitlab-sandbox!3 alberts-gitlab/gitlab-sandbox!4