Add opt-in pagination to pipeline variables API
What does this MR do and why?
GET /projects/:id/pipelines/:pipeline_id/variables returns every pipeline variable in one response.
This MR lets clients page through the list with the page and per_page parameters.
Pagination is opt-in. A request without page or per_page still gets the full list.
The shared use :pagination helper sets per_page to 20 by default, which would truncate the
response for existing clients, and REST API v4 does not allow breaking changes.
So the endpoint declares the two parameters without defaults.
For review:
- Pipeline variables are stored in one JSON artifact, or in the database for older pipelines.
Each page request still loads the full list and pages it in memory with
Kaminari.paginate_array, so pagination only caps the response size. - Database-backed variables are sorted by ID before paging, because that query has no
ORDER BY. - A client that already sends
per_pagenow gets one page with pagination headers. Before this MR the parameter was ignored. - There is no feature flag, because requests without the new parameters are unchanged.
References
- Closes https://gitlab.com/gitlab-org/gitlab/-/work_items/630130
- !256690 (merged) removed the docs note that said this endpoint was paginated.
Screenshots or screen recordings
Does not apply. This is an API-only change.
How to set up and validate locally
Validated on GDK with a pipeline that has three pipeline variables, FIRST, SECOND, and THIRD.
-
Create a pipeline with three variables:
curl --request POST \ --header "PRIVATE-TOKEN: <your_access_token>" \ --header "Content-Type: application/json" \ --data '{"ref":"main","variables":[{"key":"FIRST","value":"1"},{"key":"SECOND","value":"2"},{"key":"THIRD","value":"3"}]}' \ --url "https://gdk.test:3443/api/v4/projects/<project_id>/pipeline" -
Request the variables without pagination parameters:
curl --include --request GET \ --header "PRIVATE-TOKEN: <your_access_token>" \ --url "https://gdk.test:3443/api/v4/projects/<project_id>/pipelines/<pipeline_id>/variables"The response has all three variables and no pagination headers:
HTTP/1.1 200 OK [{"variable_type":"env_var","key":"FIRST","value":"1","raw":false},{"variable_type":"env_var","key":"SECOND","value":"2","raw":false},{"variable_type":"env_var","key":"THIRD","value":"3","raw":false}] -
Add
?per_page=2to the URL:HTTP/1.1 200 OK X-Next-Page: 2 X-Page: 1 X-Per-Page: 2 X-Total: 3 X-Total-Pages: 2 [{"variable_type":"env_var","key":"FIRST","value":"1","raw":false},{"variable_type":"env_var","key":"SECOND","value":"2","raw":false}] -
Add
?page=2&per_page=2to the URL:HTTP/1.1 200 OK X-Page: 2 X-Per-Page: 2 X-Prev-Page: 1 X-Total: 3 X-Total-Pages: 2 [{"variable_type":"env_var","key":"THIRD","value":"3","raw":false}]
Other requests against the same pipeline:
| Query | Result |
|---|---|
?page=1 |
200, all three variables, X-Per-Page: 20 |
?per_page=101 |
200, X-Per-Page: 100 |
?per_page=0 |
400, per_page has a value not allowed |
A pipeline with two database-backed variables returns them in ID order, one per page, with ?per_page=1.
MR acceptance checklist
Evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.