'Continuous deployment gitlab

Line of my .gitlab-ci.yml

IID=$(curl --verbose --request GET --header "Content-Type: application/json" --header "PRIVATE-TOKEN: ${CI_PUSH_TOKEN}" ${APP_REPO_URL}/merge_requests?author_id=xxxxxxxx\&search=${CI_COMMIT_SHORT_SHA} | jq '.[0].iid')

output jq: error (at :0): Cannot index object with number



Solution 1:[1]

Please refer to the documentation on Merge requests API and How to use the API to construct a properly formed cURL request with GitLab API before piping the result into jq.

There are a few things going on with your query.

First of all, according to the documentation, the /merge_requests endpoint will

Get all merge requests the authenticated user has access to.

This means that APP_REPO_URL needs to be the GitLab instance URL followed by /api/v4 and not the URL of the specific project.

curl "https://gitlab.example.com/api/v4/merge_requests"

If you need all merge requests for a given project, then you can use

curl "https://gitlab.example.com/api/v4/projects/:id/merge_requests"

where :id is the id of your project. See more at List project merge requests

Then, the search attribute is expecting either a title or a description and not a commit SHA:

Search merge requests against their title and description

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1