thekucays
thekucays

Reputation: 618

shell script: cat file content then use it in curl post

im trying to hit gitlab release api to update my release note description field from CHANGELOG.md file
these are what ive tried:

#!/bin/sh

releaseNote=$(cat CHANGELOG.md)
curl --header 'Content-Type: application/json' --request PUT --data '{"description": "'"${releaseNote}"'"}' --header "PRIVATE-TOKEN: mytokenhere" "https://gitlab.com/api/v4/projects/1234/releases/0.1"
#!/bin/sh

releaseNote=$(cat CHANGELOG.md)
curl --header 'Content-Type: application/json' --request PUT --data '{\"description\": \"${releaseNote}\" }' --header "PRIVATE-TOKEN: mytokenhere" "https://gitlab.com/api/v4/projects/1234/releases/0.1"

when i try to hard-code description field like this, it works

#!/bin/sh

curl --header 'Content-Type: application/json' --request PUT --data '{"description": "foo"}' --header "PRIVATE-TOKEN: mytokenhere" "https://gitlab.com/api/v4/projects/1234/releases/0.1"

and here is whats inside my CHANGELOG.md file

# Changelog

All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.

## 1.0.0 (2022-07-22)


### Features

* abc
* def

any suggestion guys?

Upvotes: 0

Views: 1444

Answers (1)

thekucays
thekucays

Reputation: 618

as per @LéaGris suggestion above, finally it works.. here is my code snippet

#!/bin/sh


# format CHANGELOG.md to proper JSON format first
releaseNote=$( jq -sR '{"description": .}' CHANGELOG.md )

# hit the API
curl --header 'Content-Type: application/json' --request PUT --data "$releaseNote" --header "PRIVATE-TOKEN: mytokenhere" "https://gitlab.com/api/v4/projects/1234/releases/0.1"

Upvotes: 1

Related Questions