Gitlab 使用工件中的链接发布作业

问题描述 投票:0回答:1

我正在致力于为 GitLab 创建自动化管道。我的目标是构建应用程序的发布版本(运行良好)并将其打包到 msi 包中(运行良好)。

在以下代码中:

release-job:  # Valid release section within the job
stage: release
image: registry.gitlab.com/gitlab-org/release-cli:latest              
script:
  - echo "Running the release job."
dependencies:
  - packaging
needs:
  - packaging 
release:
  tag_name: TestRelease
  name: 'Release TestRelease'
  description: 'Release created using the release-cli.'
  assets:
    links:
      - name: Setup.msi
        url: $(< artifact_url.txt | sed 's/^\s*|\s*$//g')

我正在尝试从

获取链接

artifact_url.txt

这导致了错误:

error =“无法创建发布:API错误响应status_code:400 消息:验证失败:链接 url 不能为空,链接 url 必须 是一个有效的 URL”版本=0.16.0

我已经尝试过同一脚本的这个版本:

release-job:  # Valid release section within the job
  stage: release
  image: registry.gitlab.com/gitlab-org/release-cli:latest                 
  script:
    -
     |
     echo "Running the release job."
     ARTIFACT_URL=$(sed 's/^\s*|\s*$//g; s/ //g' artifact_url.txt)
     ARTIFACT_URL=${ARTIFACT_URL:2}
     echo "Setup.msi download URL: $ARTIFACT_URL"
  dependencies:
    - packaging
  needs:
    - packaging 
  release:
    tag_name: TestRelease
    name: 'Release TestRelease'
    description: 'Release created using the release-cli.'
    assets:
      links:
        - name: Setup.msi
          url: $ARTIFACT_URL

即使在“url”部分中使用引号,甚至没有“$”符号,我也尝试过。但总是出现与我之前描述的相同的错误。

PS:我知道txt文件中的链接是可以的,因为我看到了它并且它工作正常。

我可以在这里寻求帮助吗?

谢谢你

url gitlab pipeline release artifacts
1个回答
0
投票

发布部分不以与脚本部分相同的方式评估变量。此限制意味着动态变量(例如您尝试在资产子部分中用于 URL 的变量)将不会按您的预期进行处理。

有 2 个步骤可以解决您面临的问题

  1. 使用脚本部分准备artifact_url.txt并动态生成包含所需URL的配置或脚本。
  2. 在脚本部分以命令行方式使用 GitLab Release CLI,而不是依赖 .gitlab-ci.yml 文件中的release关键字。

可用作模板来动态设置 URL 变量的示例代码:

release-job:  # Valid release section within the job
  stage: release
  image: registry.gitlab.com/gitlab-org/release-cli:latest
  script:
    - echo "Running the release job."
    - ARTIFACT_URL=$(sed 's/^\s*|\s*$//g; s/ //g' artifact_url.txt)
    - echo "Setup.msi download URL: $ARTIFACT_URL"
    # Now use the release-cli directly with the prepared URL
    - >
      gitlab-release create --name "Release $CI_COMMIT_TAG" --tag-name $CI_COMMIT_TAG
      --description "Release created using the release-cli."
      --assets-link "{\"name\":\"Setup.msi\",\"url\":\"$ARTIFACT_URL\"}"
  dependencies:
    - packaging
  needs:
    - packaging 
© www.soinside.com 2019 - 2024. All rights reserved.