Hey all, I am a bit boggled on this one.
If anyone has deep familiarity with the API and/or gitlab environments, would appreciate some eyeballs.
consider a desire to find an environment ID by name
PRIVATE_TOKEN="..."
PROJECT_URI="https://..."
PROJECT_ID="XX"
As per this the documentation describes precisely what I want.
https://docs.gitlab.com/ee/api/environments.html#list-environments
?name=
& ?search=
experimenting with the basic query, I can see my environments in the BULK get
curl --header "PRIVATE-TOKEN: ${PRIVATE_TOKEN}" ${PROJECT_URI}/api/v4/projects/${PROJECT_ID}/environments?per_page=100 | jq '.[] | .name' | grep master/
(snip)
"master/3524"
"master/3525"
"master/3526"
but my goal is to get the ID of a specific environment, by a specific name, so lets say I want “master/3524”
$ curl --header "PRIVATE-TOKEN: ${PRIVATE_TOKEN}" ${PROJECT_URI}/api/v4/projects/${PROJECT_ID}/environments?name=master%2F3524 | jq '.[] | .name'
(SNIP)
...
lists ALL environments!!
...
it doesn’t match, in the documentation example, it is quite clear that /
needs to be %2F
(verified https://en.wikipedia.org/wiki/Percent-encoding)
, i tried /
directly, … but of course this doesn’t work because /
is a reserved character, it needs to be %
encoded
tried the search filter as well, same problem
curl --header "PRIVATE-TOKEN: ${PRIVATE_TOKEN}" ${PROJECT_URI}/api/v4/projects/${PROJECT_ID}/environments?search=3524 | jq '.[] | .name'
...
curl --header "PRIVATE-TOKEN: ${PRIVATE_TOKEN}" ${PROJECT_URI}/api/v4/projects/${PROJECT_ID}/environments?search=master | jq '.[] | .name'
...
I wondered if it was because the environment has numerics in there … created a dev environment that doesn’t have that, still doesn’t work!
curl --header "PRIVATE-TOKEN: ${PRIVATE_TOKEN}" ${PROJECT_URI}/api/v4/projects/${PROJECT_ID}/environments?name=dev%2Ffuntime
...
kind of boggled …
getting the SPECIFIC environment does work as expected (but I need the above to work in order to get the internal gitlab environment ID)
$ curl --header "PRIVATE-TOKEN: ${PRIVATE_TOKEN}" ${PROJECT_URI}/api/v4/projects/${PROJECT_ID}/environments/904 | jq '.name'
(snip)
"master/3526"