Passing Build Information to Octopus

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.

Hi Mike,

I’m on leave today, so won’t be able to look into this in detail into Monday, but it looks like the BuildInformation and list of Commits can be sent via the same API endpoint we use when creating a deployment. It’s therefore possible that we can modify the Octopus Deploy build event handler to include this information.

Otherwise, the only option would be to call a separate Powershell / Python script or executable to push the build information. It’s not currently possible to use loops the Request Body of the HTTP Request build event handler.

It’s possible that feeding the data into Octopus via the /releases endpoint would do it, as there are similar properties there.

No worries on waiting until Monday to take a look. I’ve spent the last week or so trying to get this working, so a few more days isn’t going to make that much of a difference. If I really need to resort to a Powershell script, then it would be a bit more brittle, but so be it.

Keep me posted and enjoy your weekend!

Hi Mike,

Looking at the Octopus Deploy Swagger docs we don’t see any way to post build information to the /releases endpoint when creating a release. Although the example body for posting to the /deployments endpoint does include BuildInformation, posting this does not appear to add anything to Octopus Deploy.

We will therefore add a separate call to post to the /build-information endpoint. In our tests, this works best if we add the build information just before creating a release, otherwise the build information is listed only in the library and not on the Octopus Deploy releases page.

I’m able to manually push to the /api/build-information endpoint and it does create the build inside of Octopus. Their support team indicated to me that this was the way to go, so I’m fairly certain that’s what needs to be done. The challenge I’m having is supplying multiple commit messages in the array.

Octopus support also indicated that this information MUST be passed to Octopus prior to pushing any packages that have the same version numbers. Otherwise, the build information isn’t available to the Release because the Release creates a snapshot of the data and looks for the Build Information. Once that snapshot has been created, it can’t be edited. So it has to be pushed as Build Information prior to building the Release.

I think it has to be pushed before the Octo Push call, but I’m not 100% certain of that and didn’t test it, because their recommendation was to create the Build Information prior to pushing any packages.

If you need any help testing anything, don’t hesitate to ask.