效果如下:
![](https://blog.sdlsj.net/wp-content/uploads/2020/07/image.png)
通过curl调用GitLab的API实现
curl --ssl-no-revoke -H "JOB-TOKEN: %CI_JOB_TOKEN%" -H "Content-Type: application/json" -d "{ """name""": """Release Name""", """tag_name""": """Tag Name""", """ref""": """%CI_BUILD_REF%""", """assets""": { """links""": [{ """name""": """Asset Name""", """url""": """Asset URL""" }] } }" "%CI_API_V4_URL%/projects/%CI_PROJECT_ID%/releases"
–ssl-no-revoke是为了避免curl检测SSL证书是否吊销时出现0x80092013错误。
%CI_JOB_TOKEN%来自CI环境下的环境变量,这个Token具有创建Release的权限
%CI_BUILD_REF%表示当前执行CI的git ref
assets为可选的
%CI_API_V4_URL%/projects/%CI_PROJECT_ID%/releases为用环境变量拼接出的API地址
API详细文档见:https://docs.gitlab.com/ee/api/releases/#create-a-release