gitlabcontinuous-integrationmarkdownrelease

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


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.


Solution

  • 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.