You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

求助:.NET Publish产物无法上传至GitLab其他项目通用包仓库

问题排查与修复方案

核心问题1:curl命令换行反斜杠后存在多余空格

你的curl命令中,部分行末尾的反斜杠\后面带有空格,这会导致shell解析命令时出错——反斜杠必须是行的最后一个字符,不能跟空格。比如这一行:

--header "Private-Token:${CI_JOB_TOKEN}" \ 

反斜杠后的空格会被shell识别为参数的一部分,导致curl把后续内容拆分成错误的独立命令,进而出现"Could not resolve host: publish_output"(因为shell把--form参数里的路径拆成了新的命令)。

核心问题2:通用包URL中的ARTIFACT_NAME未使用变量

URL里的ARTIFACT_NAME是硬编码字符串,没有替换为实际的变量${ARTIFACT_NAME},这会导致GitLab通用包仓库的路径无效,触发"URL using bad/illegal format"错误。

修复后的完整配置

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:
    - echo "start upload to ${CI_API_V4_URL}/api/v4/projects/$DeployProjectId/packages/generic/${ARTIFACT_NAME}/$CI_PIPELINE_ID"
    - curl --request POST \
      --header "Private-Token:${CI_JOB_TOKEN}" \
      --header "Content-Type:multipart/form-data" \
      --form "file=@publish_output/$ARTIFACT_NAME" \
      "${CI_API_V4_URL}/api/v4/projects/$DeployProjectId/packages/generic/${ARTIFACT_NAME}/$CI_PIPELINE_ID"

额外验证点

  • 确保$ARTIFACT_NAME变量在流水线中已正确定义(比如在项目CI/CD变量中设置)
  • 检查publish_output/$ARTIFACT_NAME文件是否存在于deploy阶段的工作目录中(可通过添加ls -la publish_output命令验证)

内容的提问来源于stack exchange,提问作者Carrie Kaski

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.09 21:35:07