feat: add pagination to ci trigger command
-
Please check this box if this contribution uses AI-generated content (including content generated by GitLab Duo features) as outlined in the GitLab DCO & CLA. As a benefit of being a GitLab Community Contributor, you receive complimentary access to GitLab Duo.
Description
- chore: add explaining comments
- feat: add pagination to ci trigger command
glab --version
glab 1.57.0 ()
Related Issues
Relates to #7783 as without this fix we use the same workaround. After some local debugging I saw that the default is no pagination and page size of 20. Sometime we were lucky that the job name was on page 1.
How has this been tested?
Unit tests
See the changes in the unit test, in which a new test was added also other tests needed to be adapted to reflect the response Headers of the httpMock
Self-hosted Gitlab environment
curl -fsSL -H "PRIVATE-TOKEN: $GITLAB_TOKEN" https://git.mycompany.com/api/v4/version
{
"version": "17.10.5-ee",
"revision": "2f78e1e2cf3",
"kas": {
"enabled": false,
"externalUrl": null,
"externalK8sProxyUrl": null,
"version": null
},
"enterprise": true
}
Before the fix, I got the message of
export JOB_NAME=dummy-job
glab ci trigger "${JOB_NAME}" --repo ${CI_PROJECT_PATH} --pipeline-id ${CI_PIPELINE_ID}
invalid job ID: dummy-job
pipeline 12345678 contains no jobs.
However the pipeline has 45 jobs
Then I used the workaround as described in #7783 :
export JOB_NAME=dummy-job
JOB_ID=$(glab ci get --repo ${CI_PROJECT_PATH} --pipeline-id ${CI_PIPELINE_ID} --output json | jq -r '.jobs[]|select(.name=="'${JOB_NAME}'")|.id')
glab ci trigger "${JOB_ID}" --repo ${CI_PROJECT_PATH} --pipeline-id ${CI_PIPELINE_ID}
to verify it works if I pass numeric JOB_ID to the command. Which it did as ci get returns the full JSON.
After the fix it paginates through the api and finds the job:
export JOB_NAME=dummy-job
./bin/glab ci trigger "${JOB_NAME}" --repo ${CI_PROJECT_PATH} --pipeline-id ${CI_PIPELINE_ID}
Triggered job (ID: 987654 ), status: pending , ref: 1.0.1 , weburl: https://git.mycompany.com/dummy-group/dummy-project/-/jobs/987654 )
Screenshots (if appropriate):
Types of changes
I am unsure. Feel free to decide.
-
Bug fix (non-breaking change which fixes an issue) -
New feature (non-breaking change which adds functionality) -
Breaking change (fix or feature that would cause existing functionality to change) -
Documentation -
Chore (Related to CI or Packaging to platforms) -
Test gap
Edited by 🤖 GitLab Bot 🤖