本文介绍了如何使用发行版API在Marklab CI中的文件中使用markdown进行描述的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在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.

只需在此处中放置一个卷曲请求该文档工作正常.对于说明,文档指出允许markdown,这很棒.但是,我似乎无法弄清楚或想出一个从curl请求中的markdown文件加载描述的想法.我已经尝试过将markdown文件的内容存储在curl之前的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放在curl请求本身中,作为"description"的值.

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

对于描述"键,我想将markdown文件的内容作为值传递.

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在Marklab CI中的文件中使用markdown进行描述的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-20 03:39