GitLab Release Links API: 404 project not found

Viewed 4094

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.

enter image description here

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"
3 Answers

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"

I have the same problem, from inside a CI job.

The following is my request:

curl
  --request POST
  --header "PRIVATE-TOKEN: <my-private-token-value>"
  --data name="User Manual"
  --data url="${PACKAGE_REGISTRY_URL}${USER_MANUAL_FILENAME}"
  --data filepath="/${USER_MANUAL_FILENAME}"
  "${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/releases/${CI_COMMIT_TAG}/assets/links"

When I write the token value through a variable (eg. --header "PRIVATE-TOKEN: ${GL_TOKEN}" the request is not working and I get 404 Project not found. Otherwise, if I write the unencrypted token value (eg. --header "PRIVATE-TOKEN: glpat-xxxxx", then it works correctly. And this sounds very weird to me, since it should not be safe at all from a security point of view to write private token values around in the gitlab-ci.yml.

Related