4

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"
boring10
  • 83
  • 2
  • 7

3 Answers3

0

I switched to using a JSON content and that seemed to resolve the issue.

https://docs.gitlab.com/ee/development/documentation/restful_api_styleguide.html#post-data-using-json-content

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"
boring10
  • 83
  • 2
  • 7
0

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"
Abhishek
  • 763
  • 7
  • 18
0

If you get a 404, the other thing to check is that the project you are running your pipeline from is permitted to access artifacts from the other project.

By default a pipeline CI_JOB_TOKEN can only access the current project.

In the Gitlab menu [Project] -> Settings -> CI/CD there is a Token Access section to "Control how the CI_JOB_TOKEN CI/CD variable is used for API access between projects."

https://docs.gitlab.com/ee/ci/jobs/ci_job_token.html#allow-access-to-your-project-with-a-job-token

andyvan
  • 183
  • 2
  • 7