How to use markdown for description from a file in gitlab CI using release API

江枫思渺然 提交于 2020-01-25 06:45:08

问题


I'm using the Gitlab release API in the gitlab-ci.yml to be able to automatically create a new release when deploying.

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`

and also to just put the cat ./description.md in the curl request itself as the value of "description".

Here is the example from the docs:

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)?

Any help will be much appreciated.


回答1:


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

The variable is expanded inside double quote (see https://superuser.com/a/835589)

Example of the content of my 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.


来源:https://stackoverflow.com/questions/58689814/how-to-use-markdown-for-description-from-a-file-in-gitlab-ci-using-release-api

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!