将管道工件附加到 GitLab 中的发布

eny*_*nyo 7 gitlab gitlab-ci

在我的存储库中,仅在 \xe2\x80\x94 中检查源文件,测试代码并在管道中生成 dist 文件。然后,我希望能够标记特定版本并将该管道生成的工件附加到它。理想情况下,这一切都应该在尽可能少的手动干预下发生。

\n\n

从版本中引用管道工件的最佳方法是什么?

\n

San*_*bat 10

您可以在构建应用程序的作业之后的一个阶段中使用release-cli,将上一个作业的文件上传到版本,您将需要该构建作业 ID,您可以将其存储在工件中的文件中:

build:
  stage: build
  script:
    - echo "Build your app"
    - echo "${CI_JOB_ID}" > CI_JOB_ID.txt # This way you know the job id in the next stage
  artifacts:
    paths:
      - your_app.exe
      - CI_JOB_ID.txt
    expire_in: never
  rules:
    - if: $CI_COMMIT_TAG


release:
  stage: release
  image: registry.gitlab.com/gitlab-org/release-cli:latest
  script:
    - |
      release-cli create --name "Release $CI_COMMIT_TAG" --tag-name $CI_COMMIT_TAG \
        --assets-link "{\"name\":\"Executable file\",\"url\":\"https://gitlab.com/some/repo/-/jobs/`cat CI_JOB_ID.txt`/artifacts/file/your_app.exe\"}"
  rules:
    - if: $CI_COMMIT_TAG
Run Code Online (Sandbox Code Playgroud)

这样,每次您tag存储库时,如果管道成功,它都会创建一个版本。