Expose GIT Hash

I found a plugin, https://library.octopusdeploy.com/step-template/actiontemplate-github-create-release, which lets me create a release in my GIT repo. I plan on doing this after the release is launched to production instead of littering our GIT Repos with tags at build time.

Is there any way to:

  • Read a file from within the pacakge we are deploying?

  • Read the release notes as JSON data? (possibly storing my hash and other info in the release notes and casting it to JSON Octopus.Release.Notes)

  • Some other method to get the GIT hash that’s included with the release? Not everything is a web site, so I can’t simply hit a URL post release to get the info.

Hi Casey,

Thanks for getting in touch! If you have a file with the Git hash in it I think the easiest option is to run a script that reads the hash out of that file either as a seperate Run Script step, or as a PostDeploy script within your package deploy step, then save that value as an Output Variable (see https://octopus.com/blog/fun-with-output-variables). Then you will be able to use the Output Variable directly in the Create GitHub Release step.

For example, I made a package with a file in the root called commit.sha which contained nothing but a GIT hash. I made a deployment step called Deploy Package, then a run script step with the following script body:

$packageDir = $OctopusParameters["Octopus.Action[Deploy Package].Output.Package.InstallationDirectoryPath"]
$content = [IO.File]::ReadAllText("$packageDir\commit.sha")
Set-OctopusVariable -name "Sha" -value "$content"

You can see it first finds the installation path from the Deploy Package step, then reads out the file and saves its content to an Output Variable called Sha. That variable is then available in all following steps by using $OctopusParameters["Octopus.Action[Copy SHA to Variable].Output.Sha"], where “Copy SHA to Variable” was the name of my Run Script step.

I hope that helps.

Mark

1 Like