Upload dotnet pachage return 404

Hi

I’m the first try to upload dotnet publish file into other project where it failure, my gitlab yml look like this

publish_and_zip:
  stage: build
  script:
    - dotnet publish ${PROJECT} --no-restore -c Release -o publish_output
    - apt-get update -qy
    - apt-get install -y zip
    - cd publish_output
    - zip -r $ARTIFACT_NAME ./
  when: on_success
  needs:
    - build-job
  artifacts:
    paths:
      - publish_output/$ARTIFACT_NAME
    expire_in: 1 week
  
upload_to_generic_package_repository:
  stage: deploy
  
  dependencies:
    - publish_and_zip
  script:
    - curl --header "JOB-TOKEN:${CI_JOB_TOKEN}" --header "Content-Type:multipart/form-data" --form "file=@publish_output/$ARTIFACT_NAME" "${CI_API_V4_URL}/api/v4/projects/${DeployProject}/packages/generic/${ARTIFACT_NAME}/${CI_PIPELINE_ID}"

But it alway return {“error”:“404 Not Found”} at the end, but {DeployProject} is create by my other project which have valid project id, can I know what problem inside

Thanks for taking the time to be thorough in your request, it really helps! :blush:

Hey there,

I believe this might be authentication problem. By default, CI_JOB_TOKENs are very limited and have permissions as much as the triggerer of the job - look at the docs. Also, not sure on which GitLab you are, but for this API call, CI_JOB_TOKENs can be used only from GitLab v15.3.

I would suggest you in such cross-project pipelines, to use either Project Access Tokens or Deploy tokens (which suit better). You can create one for your DeployProject and copy the value as CI/CD Variable into the project where you run the pipeline.

But also, I think you’re missing the file name at the end of your API call… .../generic/<name>/<version>/<file_name.zip> - have a look at official example.

Hope this helps! :slight_smile:

2 Likes

Hi,

I follow your example and it’s not working, I try to add debug in the yml as below:

upload_to_generic_package_repository:
  stage: deploy
  dependencies:
    - publish_and_zip
  script:
    - echo "Debug:Contents of publish_output directory:"
    - ls -l publish_output
    - echo "Debug:ARTIFACT_NAME = $ARTIFACT_NAME"
    - echo "Starting upload to ${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/generic/$CI_PIPELINE_ID/$ARTIFACT_NAME"
    - curl --header "JOB-TOKEN:$CI_JOB_TOKEN" --upload-file publish_output/$ARTIFACT_NAME "${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/generic/$CI_PIPELINE_ID/$ARTIFACT_NAME"

and then the output result

Debug:Contents of publish_output directory:
$ ls -l publish_output
total 20256
-rw-r--r-- 1 root root 20738598 Sep 27 02:53 testfile.zip
$ echo "Debug:ARTIFACT_NAME = $ARTIFACT_NAME"
Debug:ARTIFACT_NAME = testfile.zip
$ echo "Starting upload to ${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/generic/$CI_PIPELINE_ID/$ARTIFACT_NAME"
Starting upload to https://gitlab.com/api/v4/projects/13313345/packages/generic/2446688/testfile.zip
$ curl --header "JOB-TOKEN:$CI_JOB_TOKEN" --upload-file publish_output/$ARTIFACT_NAME "${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/generic/$CI_PIPELINE_ID/$ARTIFACT_NAME"
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 19.7M  100    27  100 19.7M     13  9817k  0:00:02  0:00:02 --:--:-- 9817k
{"error":"file is missing"}
Cleaning up project directory and file based variables

can I know how to fix it ?

As I wrote…

${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/generic/$CI_PIPELINE_ID/$ARTIFACT_NAME/here-the-filename.zip

But I believe you wanted to $ARTIFACT_NAME be the filename, and $CI_PIPELINE_ID be the version, in that case you’re missing the package name after the /generic/… so:

${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/generic/my-package/$CI_PIPELINE_ID/$ARTIFACT_NAME
1 Like

Thank you, it’s all work now

1 Like