I’m trying to link up the builds created by Continua CI and pushed to Octopus Deploy so that it includes the build information about what commits and changesets are associated with the current build.
After speaking with the Octopus support team, it seems that I need to configure this manually, since the “Octo Pack” and “Octo Push” actions don’t set the build information in Octopus Deploy and it is set separately from the actual packages themselves. They recommended I do this through the API and pointed me at one of their blog articles: Manually push build information to Octopus - Octopus Deploy
I followed the instructions and generally have it working, but there’s a section of the OctopusBuildInformation where I need to provide an array of the commits with the Id and Comment as separate fields. Here’s the json that needs to be passed in, as shown by their Swagger docs:
{
"OctopusBuildInformation": {
"Branch": "string",
"BuildEnvironment": "string",
"BuildNumber": "string",
"BuildUrl": "string",
"Commits": [
{
"Comment": "string",
"Id": "string"
}
],
"VcsCommitNumber": "string",
"VcsRoot": "string",
"VcsType": "string"
},
"OverwriteMode": "FailIfExists",
"PackageId": "string",
"Replace": true,
"SpaceId": "string",
"Version": "string"
}
I’ve implemented this using an Event Handler that triggers just before the packaging stage of the build and uses an HTTP Request to send the data to my Octopus Deploy server. I’ve got almost everything working, but if there are multiple commits, I need to supply them in an array of objects with the Id field set to the commit hash and the Comment set to the comment from the commit message.
Currently, I have this effectively hardcoded as the following and it works, but only a single commit is referenced.
"Commits": [
{
"Comment": "$Source.RepoName.BuiltChangeset.Comment$",
"Id": "$Source.RepoName.BuiltChangeset.RepositoryChangeId$"
}
]
I believe that the data I need is going to be located in the $Source.RepoName.Changesets$ collection and I’ll need to iterate over each of the entries, but I don’t see an obvious way to iterate over the collection to generate a list of objects that I could somehow pass in. I’ve searched the documentation and don’t see any iteration functions or options.
In theory, I could hard-code the items using $Source.RepoName.Changesets.Item(0).Comment$ and $Source.RepoName.Changesets.Item(0).RepositoryChangeId$, but without if-conditionals, loops or something like that, I’ll run into null references which will cause the build to fail because there could be one or more
Do you have any suggestions/recommendations for how I can inject an array of objects that includes all of the commits associated with this build into the Request Body of the HTTP Request? Or am I going about this completely the wrong way?
Any help would be greatly appreciated.