How to get GitLab to render a line feed/carriage return in a release note that has been created using the API

,

Hi,

I am trying to create a new release using the API, with the contents of my CHANGELOG.md file rendered within the description and sent via JSON POST request. I aim to do this via a curl statement within a release job in .gitlab-ci.yml.

Prior to this, I have successfully embedded a link to the changelog file within the release note description using markdown syntax, e.g. [Changelog](CHANGELOG.md). However my question relates to rendering the contents of the file within the release note description.

For now, I am sending the JSON POST request via the RESTED Client and copying the Changelog file contents into the description attribute of the JSON POST request.

The release is created and I can view it at the project’s release page. Unfortunately new lines are not rendered. Following, this I have tried escaping the \r and \n characters within the description attribute of the post request, e.g.:

{"id":"<project_id>","name":"Release 1.0.0","tag_name":"v1.0.0","description":"desc\\r\\ntest"}

The release note is created but the description is rendered as desc\r\ntest. I have also tried this with:

{"id":"<project_id>","name":"Release 1.0.0","tag_name":"v1.0.0","description":"desc\\ntest"}

which rendered as desc\ntest.

To eliminate the RESTED Client as the source of the issue I have also tried sending a POST request via curl:

curl --header "Content-Type: application/json" --header "PRIVATE-TOKEN: my access token" --request POST --data '{"id":"projectid","name":"release 1.0.0","tag_name":"v1.0.0","description":"test\\r\\ndescription"}' https://gitlab.com/api/v4/projects/projectid/releases

How do I get GitLab to render a line feed/carriage return in a release note that has been created using the API?

Hi,

I ran into the same problem just now and yeah… lets just say their documentation on this isn’t very good.

Here’s what I found out after some tinkering: The release description assumes its content is markdown. If you want the release description to render a line break, you have to feed it what markdown considers a valid line break (or rather a ‘second paragraph’ since markdown works on the concept of paragraphs, not individual lines): Two line breaks directly following each other: \r\n\r\n

Using your last example the following worked for me:

curl --header "Content-Type: application/json" --header "PRIVATE-TOKEN: my access token" --request POST --data '{"id":"projectid","name":"release 1.0.0","tag_name":"v1.0.0","description":"test\r\n\r\ndescription"}' https://gitlab.com/api/v4/projects/projectid/releases
1 Like

Hi,

Many thanks @cknoerndel :sunglasses: Ok, yep now I understand why it was not working. Thanks so much for your help. Greatly appreciated :smiley:

I was hoping this would also work with release-cli, but it doesnt for me, I still see \r\n\r\n in description after creating a release… so if a poor soul like me happens to read this, what I did to make it work is to use <br />
ie: release-cli create --name "<some_value>"" --description "test<br />new line" --tag-name "<some_value>"" --ref "<some_value>" ...

PS: this also works with GitLab ci/cd jobs and release keyword: Releases | GitLab

1 Like