问题描述
我在 gitlab-ci.yml 中使用 Gitlab 发布 API,以便能够在部署时自动创建新发布.
I'm using the Gitlab release API in the gitlab-ci.yml to be able to automatically create a new release when deploying.
只需将像 here 这样的 curl 请求放入文档工作得很好.对于描述,文档声明允许降价,这很棒.但是,我似乎无法弄清楚或想出从 curl 请求中的降价文件加载描述的想法.我已经尝试在 curl 之前将 markdown 文件的内容存储在 gitlab-ci.yml 中的一个变量中,然后传递它并在 curl 中展开它,如下所示:
Simply putting a curl request like here in the docs works just fine. For the description, the docs state that markdown is allowed, which is great. However, I can't seem to figure out or come up with an idea to load a description from a markdown file within the curl request. I've already tried storing the content of the markdown file in a variable in the gitlab-ci.yml prior to the curl and then pass it and expand it within the curl like so:
# gitlab-ci.yml
...
- DESCRIPTION=`cat ./description.md`
并且也将 cat ./description.md
作为description"的值放入 curl 请求本身.
and also to just put the cat ./description.md
in the curl request itself as the value of "description".
以下是文档中的示例:
curl --header 'Content-Type: application/json' --header "PRIVATE-TOKEN: gDybLx3yrUK_HLp3qPjS" \
--data '{ "name": "New release", "tag_name": "v0.3", "description": "Super nice release", "milestones": ["v1.0", "v1.0-rc"], "assets": { "links": [{ "name": "hoge", "url": "https://google.com" }] } }' \
--request POST https://gitlab.example.com/api/v4/projects/24/releases
对于描述"键,我想将降价文件的内容作为值传递.
And for the "description" key I would like to pass the contents of a markdown file as the value.
我很惊讶还没有找到关于此的帖子或讨论,所以我怀疑我要么遗漏了一些东西(非常基本/显而易见),要么人们还没有真正使用这个功能(还)?
I was surprised to not have found a post or discussion about this already, so I suspect I'm either missing something (very basic/obvious) or folks don't really use this function (yet)?
任何帮助将不胜感激.
推荐答案
使用像你这样的变量,这个 .gitlab-ci.yml
有效:
Using the variable like you, this .gitlab-ci.yml
works :
create_release:
script:
- DESCRIPTION=$(cat description.md)
- |
curl --silent --request POST --header "Content-Type:application/json" \
--header "PRIVATE-TOKEN: TOKEN" \
--data '{"name":"New release","tag_name":"v0.3", "description":"'"$DESCRIPTION"'","assets":{"links":[{"name":"hoge","url":"https://google.com"}]}}' \
https://gitlab.bankassembly.com/api/v4/projects/369/releases
变量在双引号内展开(参见https://superuser.com/a/835589)
The variable is expanded inside double quote (see https://superuser.com/a/835589)
我的description.md
的内容示例:
## CHANGELOG\r\n\r\n- Escape label and milestone titles to prevent XSS in GFM autocomplete. !2740\r\n- Prevent private snippets from being embeddable.\r\n- Add subresources removal to member destroy service.
这篇关于如何使用发布 API 从 gitlab CI 中的文件中使用 Markdown 进行描述的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!