Release 使用技巧
相关参考:
解决 release-cli: command not found
release-cli 用于在 gitlab 上创建一条 release 记录。
使用 release 功能前要在 gitlab-runner 所在的服务器上手动安装 release-cli,见文档:https://docs.gitlab.com/ee/user/project/releases/release_cli.html#install-the-release-cli-for-the-shell-executor
注意安装时需要 root 权限:
sudo curl --location --output /usr/local/bin/release-cli "https://gitlab.com/api/v4/projects/gitlab-org%2Frelease-cli/packages/generic/release-cli/latest/release-cli-linux-amd64"
设为可执行文件:
sudo chmod +x /usr/local/bin/release-cli
Test:
release-cli -v
附 release-cli 的使用文档:https://gitlab.com/gitlab-org/release-cli/-/tree/master/docs
永久定向到最新的 Release
https://gitlab.yitasoft.com/help/user/project/releases/index#permanent-link-to-latest-release
示例: https://gitlab.yitasoft.com/yitasoft-team/yt-official-website-v3/-/releases/permalink/latest
部署最新版本
首先是拿到最新版的 Release Asset(需要用户身份认证,不支持API认证):https://gitlab.yitasoft.com/help/user/project/releases/index#permanent-link-to-latest-release
只能通过分支名称在 API 中获取 Artifacts
文档:https://docs.gitlab.com/15.2/ee/api/job_artifacts.html#download-the-artifacts-archive
若在 master 打了一个名叫 v1.0.0 的标签,对应能调用成功的通地址【ref_name】应为 master 非 v1.0.0。
接口地址示例:
- 正确:
/api/v4/projects/$CI_PROJECT_ID/jobs/artifacts/$CI_COMMIT_BRANCH/raw/dist.zip?job=release-zip(注意 $CI_COMMIT_BRANCH 不一定有值。例如打 Tag 触发流水线时,不存在 $CI_COMMIT_BRANCH) - 错误:
/api/v4/projects/$CI_PROJECT_ID/jobs/artifacts/$CI_COMMIT_TAG/raw/dist.zip?job=release-zip