Add API endpoint to list files in job artifacts archive

What does this MR do?

Adds a new API endpoint to list files and directories within a job's artifacts archive:

GET /projects/:id/jobs/:job_id/artifacts/tree

This endpoint reads artifact metadata without extracting the archive, making it efficient for browsing large artifacts programmatically.

Why?

Addresses long-standing feature requests:

  • #31448 - Jobs API: List Files in Artifact zip file
  • #24186 (closed) - Get artifact archive file list with Jobs API

Currently, users can only download entire archives or specific files (if they know the path). The web UI has browse functionality, but this wasn't exposed via API.

How?

Leverages the existing artifact metadata system used by the web UI's "Browse" button:

  • Uses build.artifacts_metadata_entry() to read metadata without extraction
  • Supports optional path parameter to browse subdirectories
  • Supports recursive parameter for full listing
  • Includes proper authorization (same as artifact download)
  • Supports CI/CD job tokens for cross-project access

How to test

# List root of artifacts
curl --header "PRIVATE-TOKEN: <token>" \
  "https://gitlab.example.com/api/v4/projects/1/jobs/42/artifacts/tree"

# Browse subdirectory
curl --header "PRIVATE-TOKEN: <token>" \
  "https://gitlab.example.com/api/v4/projects/1/jobs/42/artifacts/tree?path=coverage"

# Recursive listing
curl --header "PRIVATE-TOKEN: <token>" \
  "https://gitlab.example.com/api/v4/projects/1/jobs/42/artifacts/tree?recursive=true"

# Example response

[
  {"name": "coverage", "path": "coverage/", "type": "directory", "mode": "040755"},
  {"name": "test.log", "path": "test.log", "type": "file", "size": 1234, "mode": "100644"}
]

Merge request reports

Loading