如何在 GitLab 中创建发布?

How to create releases in GitLab?

我创建了一个私有存储库,然后将其更改为 public 存储库。但是,我找不到任何释放方法。是否可以在 GitLab 中创建版本?如果有,它们是如何完成的?

如果你说的是GitHub-like release, where you associate one or several binaries to a tag,那么不,GitLab 还没有包含这个功能

您有一个 suggestion in progress,已接受 Pull Request。

2015 年 11 月更新:正如我在“", GitLab 8.2 supports releases.

中提到的

With releases you can now add a Markdown-formatted message to any Git tag and attach any number of files to it.

注意:its release API暂不支持文件附件。

Keelan mentions that issue 31221 正在跟踪该请求。


GitLab 11.7(2019 年 1 月)增加了在 GitLab 中创建版本并在摘要页面上查看它们的功能。

Releases are a snapshot in time of the source, links, and other metadata or artifacts associated with a released version of your code, and allow for users of your project to easily discover the latest released version of your code.


GitLab 12.6(2019 年 12 月)添加“自动发布证据收集以支持审计”

GitLab Releases now have a new Evidence collection entry in which you can find a snapshot of the Release’s metadata in JSON format. This snapshot can be leveraged as a chain of custody to support review and compliance processes, such as audits.

参见 issue 26019 and documentation


GitLab 12.10(2020 年 4 月)允许:

Compare Release Evidence over time

(仅限 Premium+ 版)


GitLab 13.2 (July 2020) 添加:

Create releases from .gitlab-ci.yml

In 12.10, we introduced a way for you to automatically create release tags from the .gitlab-ci.yml file.
Now we’ve made it easier and more natural to use by exposing the release keyword as a step the GitLab Runner can parse. You no longer need to add a script to call the Release API to create a release.
Instead, you can simply add the correct parameters to your CI/CD file.

参见 documentation and issue


GitLab 13.5(2020 年 10 月)现在有:

Attach binary assets to Releases

If you aren’t currently using GitLab for your releases because you can’t attach binaries to releases, your workflow just got a lot simpler.

You now have the ability to attach binaries to a release tag from the gitlab.ci-yml. This extends support of Release Assets to include binaries, rather than just asset links or source code. This makes it even easier for your development teams to adopt GitLab and use it to automate your release process.

See Documentation and Issue.


GitLab 13.7(2020 年 12 月):

Define your release description in an external file

If you create releases in your pipelines via your project’s .gitlab-ci.yml file, you’ve probably found it difficult to maintain each release’s description.

In GitLab 13.7, you can now define your release description in a source-controlled or auto-generated file and call it from .gitlab-ci.yml.
Doing so loads the file’s content into your release description as Markdown.

This makes releases easier for you to create, maintain, and use with version control and is especially useful if you want to auto-generate your changelogs.
Huge thanks to Nejc Habjan and Siemens for a great community contribution!

See Documentation and Issue.


参见 GitLab 13.10(2021 年 3 月)

Create a release from an existing tag

Previously, creating a release was supported only for new tags. In GitLab 13.10, you can now create a release by selecting an existing tag, something that will give you more flexibility when planning releases.

See Documentation and Issue.


GitLab 13.12(2021 年 5 月)

release: keyword supports asset links

Since GitLab 13.2, you’ve been able to use the release: keyword, in conjunction with the release-cli, to create a release.

The release: keyword has now been extended to include support for asset links so that you can create releases and attach files to them in a single .gitlab-ci.yml release job.

See Documentation and Issue.

2015 年 11 月更新:GitLab 8.2 现在支持发布。

凭借其 API,您现在可以 create and update a relase associated to a tag。 目前,只能将发行说明(降价文本和附件)添加到 git 标签(又名发行版)。

使用 gitlab 标签。

创建一个带有标签名称和提交说明的标签 git tag -a v1.05 -m "1st stabe release

推送更改 git push origin --tag

我还没弄清楚如何在 gitlab 上使用 markdown 发行说明,它允许您添加链接。您可能必须手动完成或使用他们的休息 api.

直接来源:https://docs.gitlab.com/ee/university/training/topics/tags.html

要在 GitLab 网站上创建一个版本:

  1. 转到您的存储库
  2. 在菜单中选择 存储库 > 标签
  3. 为您的应用版本添加标签。例如,v1.3.1.
  4. 添加有关版本的消息(标题)。例如,Release 1.3.1.
  5. 添加说明版本详细信息的注释。 (不是可选的。在标签中添加注释是发布的原因。)
  6. 单击创建标签

该版本现在将显示在 项目> 版本 下。现在在 GitLab documentation. GitLab recommends that you use the Release API 阅读更多内容,但他们的文档很难理解。不过,这将是使用 CI/CD 自动执行所有操作的首选方法。

"modern"Git实验室中的版本不仅仅是 Git 标签。我已经就这个确切的主题写了一篇

简而言之,发布的创建包括以下步骤:


1) 为您的提交创建一个标签

git tag -a MY_TAG_NAME 30728cab


2) 将标签推送到您的远程存储库

git push REMOTE_REPO_NAME REMOTE_BRANCH_NAME MY_TAG_NAME


3) 上传文件

curl --request POST --header "Private-Token: YOUR_PRIVATE_TOKEN" --form "file=@/PATH/TO/THE/FILE/file.txt" "https://MY_GITLAB_HOSTING.COM/api/v4/projects/MY_PROJECT_ID/uploads"


警告: 没有官方方法可以从 GitLab 存储库中删除上传的二进制文件 - 我建议将其保存到一些其他主机,只需保存 link!


4) 创建一个版本

curl --request POST --header 'Content-Type: application/json' --header "Private-Token: YOUR_PRIVATE_TOKEN" --data '{"name": "MY_RELEASE_NAME", "tag_name": "MY_TAG_NAME", "description": "Release with the binary LINK_TO_YOUR_BINARY"}' "https://MY_GITLAB_HOSTING.COM/api/v4/projects/MY_PROJECT_ID/releases"


最后,我强烈建议您主要看一下我以前的 linked 答案,因为那里解释了很多东西,并且附有有用的 Bash 脚本!