'GitLab Release Links API: 404 project not found
I'm trying to add an asset to a GitLab release but I keep getting {"message":"404 Project Not Found"} when trying to add a link. I was trying to follow https://docs.gitlab.com/13.7/ee/api/releases/links.html#create-a-link, but I am either crazy or missing something. I have echoed the URLs for both ${PACKAGE_REGISTRY_URL}/${PKG_VERSION}/${LINUX} and ${RELEASE_REGISTRY_URL}/${CI_PROJECT_ID}/releases/v${PKG_VERSION}/assets/links and both are valid, and appear to be correct, links. If I use the first one (PACKAGE_URL) then I get a download of the file that I am wanting. If I use the (RELEASE_REGISTRY_URL) then I get a page that shows an empty array.
I have also verified that all variables do have the correct values that I would be expecting. I have tried with and without the link_type option.
# This works with no problem
curl --header "JOB-TOKEN: $CI_JOB_TOKEN" \
--upload-file bin/${LINUX} "${PACKAGE_REGISTRY_URL}/${PKG_VERSION}/${LINUX}"
# This returns: {"message":"404 Project Not Found"}
curl --request POST \
--header "JOB-TOKEN: $CI_JOB_TOKEN" \
--data link_type="other" \
--data name="${LINUX}" \
--data url="${PACKAGE_REGISTRY_URL}/${PKG_VERSION}/${LINUX}" \
--data filepath="bin/${LINUX}" \
"${RELEASE_REGISTRY_URL}/${CI_PROJECT_ID}/releases/v${PKG_VERSION}/assets/links"
"${PACKAGE_REGISTRY_URL}/${PKG_VERSION}/${LINUX}" -> # https://gitlab.com/api/v4/projects/<myidishere>/packages/generic/test/1.1.0/test-1.1.0-linux
"${RELEASE_REGISTRY_URL}/${CI_PROJECT_ID}/releases/v${PKG_VERSION}/assets/links" -> # https://gitlab.com/api/v4/projects/<myidishere>/releases/v1.1.0/assets/links
Here is the example that is in the GitLab documentation.
curl --request POST \
--header "PRIVATE-TOKEN: <your_access_token>" \
--data name="hellodarwin-amd64" \
--data url="https://gitlab.example.com/mynamespace/hello/-/jobs/688/artifacts/raw/bin/hello-darwin-amd64" \
--data filepath="/bin/hellodarwin-amd64" \
"https://gitlab.example.com/api/v4/projects/20/releases/v1.7.0/assets/links"
Solution 1:[1]
This is a permission issue. While invoking gitlab API, we use commonly use CI_JOB_TOKEN and CI_JOB_TOKEN copies the permission of the user running it.
Please make yourself the owner(or grant higher privilege) of the repo you are working on.
The below script works only when I have a higher privilege for accessing releases API.
- |-
PAYLOAD=$(cat << JSON
{
"tag_name": "$VERSION",
"ref": "$CI_COMMIT_SHA"
}
JSON
)
- |
curl --fail-with-body \
--data-binary "${PAYLOAD}" \
--header "Content-Type: application/json" \
--header "Accept: application/json" \
--header "Job-Token: ${CI_JOB_TOKEN}" \
--request POST \
"https://git.ivxs.uk/api/v4/projects/${CI_PROJECT_ID}/releases"
Solution 2:[2]
I switched to using a JSON content and that seemed to resolve the issue.
curl --request POST \
--header "PRIVATE-TOKEN: $CI_JOB_TOKEN" \
--header "content-type: application/json" \
--data '{"name": "${LINUX}", "url": "${PACKAGE_REGISTRY_URL}/${PKG_VERSION}/${LINUX}"}' \
--url "${RELEASE_REGISTRY_URL}/${CI_PROJECT_ID}/releases/v${PKG_VERSION}/assets/links"
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 | |
| Solution 2 | boring10 |

