文档
使用
基于官方 Docker 镜像
# https://gitlab.com/gitlab-org/release-cli/-/blob/master/.gitlab/ci/release.yml
release-from-tag:
image: registry.gitlab.com/gitlab-org/release-cli
stage: release
needs:
- 'generate_description'
- 'upload binaries to generic package for tag'
rules:
- if: '$CI_COMMIT_TAG' # Run this job when a tag is created manually
script:
- echo "Creating a release for $CI_COMMIT_TAG"
release:
name: "Release $CI_COMMIT_TAG"
description: '$DESCRIPTION'
tag_name: '$CI_COMMIT_TAG'
ref: '$CI_COMMIT_TAG'
# darwin/amd64 darwin/arm64 freebsd/386 freebsd/amd64 freebsd/arm linux/386 linux/amd64 linux/arm linux/arm64 linux/ppc64le windows/386 windows/amd64
assets:
links:
- name: 'darwin/amd64'
url: "$PACKAGE_REGISTRY_URL/$CI_COMMIT_TAG/release-cli-darwin-amd64"
direct_asset_path: '/bin/release-cli-darwin-amd64'
- name: 'darwin/arm64'
url: "$PACKAGE_REGISTRY_URL/$CI_COMMIT_TAG/release-cli-darwin-arm64"
direct_asset_path: '/bin/release-cli-darwin-arm64'
- name: 'freebsd/386'
url: "$PACKAGE_REGISTRY_URL/$CI_COMMIT_TAG/release-cli-freebsd-386"
direct_asset_path: '/bin/release-cli-freebsd-386'
- name: 'freebsd/amd64'
url: "$PACKAGE_REGISTRY_URL/$CI_COMMIT_TAG/release-cli-freebsd-amd64"
direct_asset_path: '/bin/release-cli-freebsd-amd64'
- name: 'freebsd/arm'
url: "$PACKAGE_REGISTRY_URL/$CI_COMMIT_TAG/release-cli-freebsd-arm"
direct_asset_path: '/bin/release-cli-freebsd-arm'
- name: 'linux/386'
url: "$PACKAGE_REGISTRY_URL/$CI_COMMIT_TAG/release-cli-linux-386"
direct_asset_path: '/bin/release-cli-linux-386'
- name: 'linux/amd64'
url: "$PACKAGE_REGISTRY_URL/$CI_COMMIT_TAG/release-cli-linux-amd64"
direct_asset_path: '/bin/release-cli-linux-amd64'
- name: 'linux/arm'
url: "$PACKAGE_REGISTRY_URL/$CI_COMMIT_TAG/release-cli-linux-arm"
direct_asset_path: '/bin/release-cli-linux-arm'
- name: 'linux/arm64'
url: "$PACKAGE_REGISTRY_URL/$CI_COMMIT_TAG/release-cli-linux-arm64"
direct_asset_path: '/bin/release-cli-linux-arm64'
- name: 'linux/ppc64le'
url: "$PACKAGE_REGISTRY_URL/$CI_COMMIT_TAG/release-cli-linux-ppc64le"
direct_asset_path: '/bin/release-cli-linux-ppc64le'
- name: 'windows/386'
url: "$PACKAGE_REGISTRY_URL/$CI_COMMIT_TAG/release-cli-windows-386.exe"
direct_asset_path: '/bin/release-cli-windows-386.exe'
- name: 'windows/amd64'
url: "$PACKAGE_REGISTRY_URL/$CI_COMMIT_TAG/release-cli-windows-amd64.exe"
direct_asset_path: '/bin/release-cli-windows-amd64.exe'
基于命令行工具
CI_JOB_TOKEN:流水线运行时的 作业 Token
CI_API_V4_URL:GitLab API 地址前缀,如:https://gitlab.xuxiaowei.com.cn/api/v4
CI_PROJECT_ID:项目ID
CI_COMMIT_TAG:Git 标签
app/build/outputs/apk/release/app-release.apk:要发布的软件
/packages/generic/app/${CI_COMMIT_TAG}/app-release.apk
app:软件名称
CI_COMMIT_TAG:标签名称
app-release.apk:发布软件的 URL 文件名称
# 上传发布到 通用软件包仓库
# 如果有多个软件需要上传,执行多次命令即可
curl --header "JOB-TOKEN: $CI_JOB_TOKEN" --upload-file app/build/outputs/apk/release/app-release.apk "${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/generic/app/${CI_COMMIT_TAG}/app-release.apk"
# 创建发布
# 发布中引入 通用软件包仓库 URL,支持多文件
release-cli create --name "Release $CI_COMMIT_TAG" --tag-name $CI_COMMIT_TAG --assets-link "{\"name\":\"app-release.apk\",\"url\":\"${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/generic/app/${CI_COMMIT_TAG}/app-release.apk\"}"
# 仅在标签流水线上运行
if [ -n "$CI_COMMIT_TAG" ]; then
curl --header "JOB-TOKEN: $CI_JOB_TOKEN" --upload-file app/build/outputs/apk/release/app-release.apk "${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/generic/app/${CI_COMMIT_TAG}/app-release.apk"
./release-cli create --name "Release $CI_COMMIT_TAG" --tag-name $CI_COMMIT_TAG \
--assets-link "{\"name\":\"app-release.apk\",\"url\":\"${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/generic/app/${CI_COMMIT_TAG}/app-release.apk\"}"
fi
帮助文档
xuxiaowei@172 ~/Downloads BINARY_NAME=release-cli-darwin-arm64
xuxiaowei@172 ~/Downloads curl "https://gitlab.com/api/v4/projects/gitlab-org%2Frelease-cli/packages/generic/release-cli/latest/$BINARY_NAME" --output release-cli
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 8493k 100 8493k 0 0 1608k 0 0:00:05 0:00:05 --:--:-- 2086k
xuxiaowei@172 ~/Downloads ./release-cli -h
NAME:
release-cli - A CLI tool that interacts with GitLab's Releases API
USAGE:
help [global options] command [command options] [arguments...]
VERSION:
0.24.0
DESCRIPTION:
CLI tool that interacts with GitLab's Releases API https://docs.gitlab.com/ee/api/releases/.
All configuration flags will default to GitLab's CI predefined environment variables (https://docs.gitlab.com/ee/ci/variables/predefined_variables.html).
To override these values, use the [GLOBAL OPTIONS].
Get started with release-cli https://gitlab.com/gitlab-org/release-cli.
AUTHOR:
GitLab Inc. <support@gitlab.com>
COMMANDS:
create Create a Release using GitLab's Releases API https://docs.gitlab.com/ee/api/releases/#create-a-release
create-from-file Create a Release using GitLab's Releases API https://docs.gitlab.com/ee/api/releases/#create-a-release
get Get a Release by tag name using GitLab's Releases API https://docs.gitlab.com/ee/api/releases/index.html#get-a-release-by-a-tag-name
update Update a release using GitLab's Releases API https://docs.gitlab.com/ee/api/releases/#update-a-release
help, h Shows a list of commands or help for one command
GLOBAL OPTIONS:
--server-url value The base URL of the GitLab instance, including protocol and port, for example https://gitlab.example.com:8080 [$CI_SERVER_URL]
--job-token value Job token used for authenticating with the GitLab Releases API (default: ) [$CI_JOB_TOKEN]
--project-id value The current project's unique ID; used by GitLab CI internally [$CI_PROJECT_ID]
--timeout value HTTP client's timeout in Go's duration format https://golang.org/pkg/time/#ParseDuration (default: 30s) [$RELEASE_CLI_TIMEOUT]
--private-token value Private token used for authenticating with the GitLab Releases API, requires api scope https://docs.gitlab.com/ee/user/profile/personal_access_tokens.html, overrides job-token (default: ) [$GITLAB_PRIVATE_TOKEN]
--additional-ca-cert-bundle value Configure a custom SSL CA certificate authority, can be a path to file or the content of the certificate [$ADDITIONAL_CA_CERT_BUNDLE]
--insecure-https Set to true if you want to skip the client verifying the server's certificate chain and host name (default: false) [$INSECURE_HTTPS]
--debug Set to true if you want extra debug output when running release-cli (default: false) [$DEBUG]
--help, -h Show help (default: false)
--version, -v Print the version (default: false)
xuxiaowei@172 ~/Downloads