Multiline release notes when creating release using API

We’re using the API to create a release. Instead of just a 1-line release notes we want to create a multi-line pretty output from Git and send that (formatted with line breaks) over with the new release so that the nice multi-line pretty Git output shows up as release notes.

Can the API handle this? How would we do it?

Hi Michael,

Could you send through the command you use to get your Git logs? As we use markdown to format the release notes in Octopus you’ll need an extra new line at the end of each commit.

The below script will write the git log (which formats the output as a markdown list) output to a temp file and then reads the file back into the ReleaseNotes property of the object passed to our API.

$gitoutputFile = [System.IO.Path]::GetTempFileName()

(& git log -10 --pretty=format:'- %h - %s (%cr) <%an>' --abbrev-commit) | Out-File -FilePath $gitoutputFile

$header = @{ "X-Octopus-ApiKey" = $OctopusAPIKey }

# customise the fields below as required:
$body = @{
  ProjectId = "<YourProjectId>"
  ChannelId = "<YourChannelId>"
  Version = "<YourVersion>"
  ReleaseNotes = [System.IO.File]::ReadAllText($gitoutputFile)
  SelectedPackages = @(
      StepName = "<YourStepName>"
      Version = "<YourPackageName>"

Invoke-WebRequest $OctopusURL/api/releases?ignoreChannelRules=false -Method POST -Headers $header -Body ($body | ConvertTo-Json)

I hope that helps.

Thank you and kind regards,

Here’s the Git command we are using. Is there more formatting we need to do?

git log --pretty=format:"%h - %an, %ar : %s"

Hi Michael,

To format it as a list, prepend a - to your format (i.e. - "%h - %an, %ar : %s"), otherwise add a %n (newline) to the end of the format (i.e. "%h - %an, %ar : %s%n").

As we’re rendering it as markdown there needs to be an empty line between each line as otherwise it’s just treated as one long string.

I hope that helps.

Thank you and best regards,

But do I still need a newline if I use the prepended “-”?

Also in your first post the hyphen is within the quotes. But in the latest post it’s outside the quotes. Which is the correct position?

Hey Michael,

Sorry the - should be within the quotes, and if you prepend with - you don’t need the newline %n (as that will render the release notes as a list, and the newline is implied by markdown).


Thanks, but the markup does not work for me, so I’m going to invoke good old HTML.