URL to download latest artifact does not respect the job query parameter
Summary
While using the URL documented in https://docs.gitlab.com/ce/user/project/pipelines/job_artifacts.html#downloading-the-latest-artifacts I noticed that the URL does not respect the job parameter embedded in the URL.
The URL works when the last pipeline with artifacts contains the desired job. But when the last pipeline does not contain the desired job, it seems that the last pipeline is used anyway and the result is that you get HTTP 404 when the artifacts archive does not contain the file that you are looking for.
Steps to reproduce
- Add a scheduled pipeline that builds a different set of files as artifacts (but which also targets the same branch, aka master)
- Try the
https://example.com/<namespace>/<project>/-/jobs/artifacts/<ref>/raw/<path_to_file>?job=<job_name>
URL targeting the scheduled job and a path to a file that only exists in the artifacts generated by the scheduled job. - See that it works when the sheduled pipeline is the most recent pipeline.
- See that it returns HTTP 404 when the regular pipeline is the most recent pipeline.
Example Project
I have the problem here: https://salsa.debian.org/qa/distro-tracker
Here's a scheduled job named "sample-database" building "data/distro-tracker.sqlite" as artifact: https://salsa.debian.org/qa/distro-tracker/pipelines/5559 https://salsa.debian.org/qa/distro-tracker/-/jobs/14255
Here's the URL that should download "data/distro-tracker.sqlite" out of the above scheduled job: https://salsa.debian.org/qa/distro-tracker/-/jobs/artifacts/master/raw/data/distro-tracker.sqlite?job=sample-database
This was experienced with GitLab CE 10.6.3 on salsa.debian.org.
What is the current bug behavior?
The download URL returns HTTP 404.
What is the expected correct behavior?
The download URL should return the desired artifact file.
The code should correctly identify the last occurrence of the job indicated in the query parameter and try to download the file out of the artifacts generated by this job.
Possible fixes
I have no idea of a possible fix, but I guess one should start look into the problem from here: https://gitlab.com/gitlab-org/gitlab-ce/blob/master/app/controllers/projects/artifacts_controller.rb#L91
I guess the latest_successful_builds_for
returns a single entry for the reference without taking into account the job name and so the following find_by is useless.
https://gitlab.com/gitlab-org/gitlab-ce/blob/master/app/models/project.rb#L556