Creating a changelog in a pipeline job

In my pipeline, for the master branch, I’ve decided that I’d like to keep track of what each new build will contain – for debug, traceability, auditing purposes and what not…

After the flow of tests > Docker build & push, Kubernetes deployment & verification have all passed, this is the time to generate the changelog, as the last task for the pipeline after everything else has passed successfully.

Here’s how it’s done (partial snippet):

sh '''
   changelog=$(git log `git describe --tags --abbrev=0 HEAD^`..HEAD --oneline --no-merges)
   jq -n --arg tagname "v0.0.$BUILD_NUMBER"   \
      --arg name "Release v0.0.$BUILD_NUMBER" \
      --arg body "$changelog"                 \
      '{"tag_name": $tagname, "target_commitish": "master", "name": $name, "body": $body, "draft": false, "prerelease": false}'  |
   curl -d@- https://github.ibm.com/api/v3/repos/my-org-name/my-repo-name/releases?access_token=$JENKINSBOT_GHE_ACCESS_TOKEN_PSW
'''

As you can see, you will need jq installed for this.

The end result is quite nice: