GitHub - Create Release

Octopus.Script exported 2018-02-28 by dario-l belongs to ‘GitHub’ category.

Create a release for a Github Repository.

Parameters

When steps based on the template are included in a project’s deployment process, the parameters below can be set.

Version Number

versionNumber = #{Octopus.Release.Number}

The version number for this release

Commitish

commitId = master

Specifies the commitish value that determines where the Git tag is created from. Can be any branch or commit SHA. Unused if the Git tag already exists.

Release Notes

releaseNotes = #{Octopus.Release.Notes}

The notes to accompany this GitHub release. Defaults to the release notes of the release.

Owner

gitHubUsername

The owner of the repository.

Repository

gitHubRepository

The repository to create the release for.

Api Token

gitHubApiKey

The GitHub API key

Draft

draft = false

Set to true to mark this as a draft release (not visible to users)

PreRelease

preRelease = false

Set to true to mark this as a pre-release version

Script body

Steps based on this template will execute the following PowerShell script.

[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12

$formattedVersionNumber = [string]::Format("v{0}", $versionNumber)
$isDraft = [bool]::Parse($draft)
$isPrerelease = [bool]::Parse($preRelease)

$releaseData = @{
    tag_name = $formattedVersionNumber;
    target_commitish = $commitId;
    name = $formattedVersionNumber;
    body = $releaseNotes;
    draft = $isDraft;
    prerelease = $isPrerelease;
}
$json = (ConvertTo-Json $releaseData -Compress)
$releaseParams = @{
    Uri = "https://api.github.com/repos/$gitHubUsername/$gitHubRepository/releases";
    Method = 'POST';
    Headers = @{
        Authorization = 'Basic ' + [Convert]::ToBase64String(
            [Text.Encoding]::ASCII.GetBytes($gitHubApiKey + ":x-oauth-basic")
        );
    }
    ContentType = 'application/json; charset=utf-8';
    Body = [System.Text.Encoding]::UTF8.GetBytes($json)
}

Write-Host "Creating release $formattedVersionNumber for $commitId."
$result = Invoke-RestMethod @releaseParams

Write-Host "Release successfully created."
$result

Provided under the Apache License version 2.0.

Report an issue

To use this template in Octopus Deploy, copy the JSON below and paste it into the Library → Step templates → Import dialog.

{
  "Id": "7a6704f9-c675-4dd2-bb2d-5fba374fd439",
  "Name": "GitHub - Create Release",
  "Description": "Create a release for a Github Repository.",
  "Version": 5,
  "ExportedAt": "2018-02-28T02:37:27.534+00:00",
  "ActionType": "Octopus.Script",
  "Author": "dario-l",
  "Parameters": [
    {
      "Name": "versionNumber",
      "Label": "Version Number",
      "HelpText": "The version number for this release",
      "DefaultValue": "#{Octopus.Release.Number}",
      "DisplaySettings": {
        "Octopus.ControlType": "SingleLineText"
      }
    },
    {
      "Name": "commitId",
      "Label": "Commitish",
      "HelpText": "Specifies the commitish value that determines where the Git tag is created from. Can be any branch or commit SHA. Unused if the Git tag already exists.",
      "DefaultValue": "master",
      "DisplaySettings": {
        "Octopus.ControlType": "SingleLineText"
      }
    },
    {
      "Name": "releaseNotes",
      "Label": "Release Notes",
      "HelpText": "The notes to accompany this GitHub release. Defaults to the release notes of the release.",
      "DefaultValue": "#{Octopus.Release.Notes}",
      "DisplaySettings": {
        "Octopus.ControlType": "MultiLineText"
      }
    },
    {
      "Name": "gitHubUsername",
      "Label": "Owner",
      "HelpText": "The owner of the repository.",
      "DefaultValue": null,
      "DisplaySettings": {
        "Octopus.ControlType": "SingleLineText"
      }
    },
    {
      "Name": "gitHubRepository",
      "Label": "Repository",
      "HelpText": "The repository to create the release for.",
      "DefaultValue": null,
      "DisplaySettings": {
        "Octopus.ControlType": "SingleLineText"
      }
    },
    {
      "Name": "gitHubApiKey",
      "Label": "Api Token",
      "HelpText": "The GitHub [API key](https://github.com/blog/1509-personal-api-tokens)",
      "DefaultValue": null,
      "DisplaySettings": {
        "Octopus.ControlType": "Sensitive"
      }
    },
    {
      "Name": "draft",
      "Label": "Draft",
      "HelpText": "Set to true to mark this as a draft release (not visible to users)",
      "DefaultValue": "false",
      "DisplaySettings": {
        "Octopus.ControlType": "Checkbox"
      }
    },
    {
      "Name": "preRelease",
      "Label": "PreRelease",
      "HelpText": "Set to true to mark this as a pre-release version",
      "DefaultValue": "false",
      "DisplaySettings": {
        "Octopus.ControlType": "Checkbox"
      }
    }
  ],
  "Properties": {
    "Octopus.Action.Script.ScriptBody": "[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12\n\n$formattedVersionNumber = [string]::Format(\"v{0}\", $versionNumber)\n$isDraft = [bool]::Parse($draft)\n$isPrerelease = [bool]::Parse($preRelease)\n\n$releaseData = @{\n    tag_name = $formattedVersionNumber;\n    target_commitish = $commitId;\n    name = $formattedVersionNumber;\n    body = $releaseNotes;\n    draft = $isDraft;\n    prerelease = $isPrerelease;\n}\n$json = (ConvertTo-Json $releaseData -Compress)\n$releaseParams = @{\n    Uri = \"https://api.github.com/repos/$gitHubUsername/$gitHubRepository/releases\";\n    Method = 'POST';\n    Headers = @{\n        Authorization = 'Basic ' + [Convert]::ToBase64String(\n            [Text.Encoding]::ASCII.GetBytes($gitHubApiKey + \":x-oauth-basic\")\n        );\n    }\n    ContentType = 'application/json; charset=utf-8';\n    Body = [System.Text.Encoding]::UTF8.GetBytes($json)\n}\n\nWrite-Host \"Creating release $formattedVersionNumber for $commitId.\"\n$result = Invoke-RestMethod @releaseParams\n\nWrite-Host \"Release successfully created.\"\n$result",
    "Octopus.Action.Script.Syntax": "PowerShell"
  },
  "Category": "GitHub",
  "HistoryUrl": "https://github.com/OctopusDeploy/Library/commits/master/step-templates//opt/buildagent/work/75443764cd38076d/step-templates/github-tag-release.json",
  "Website": "/step-templates/7a6704f9-c675-4dd2-bb2d-5fba374fd439",
  "Logo": "iVBORw0KGgoAAAANSUhEUgAAAMgAAADICAMAAACahl6sAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAADZQTFRF////GBYW8fDwUlBQi4qKJiUlqKenNTMzxcXFb25u4uLiQ0JC1NPTYF9fmpmZt7a2fXx8qKioXgENRQAABcNJREFUeNrsXel2tSoMPcyDovb9X/b2W7c9PYMIQhJsV/bvVs42IwnE243BYDAYDAaDwWAwGAwGg8Fg/EFEb7VO6o6ktfXxV1GQXqdJZDAl7eVvIGFDlsMDm2AvTWbWFSTuZPR8UZvYnDgJt8XradQkmjBdSsfiZkQzz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oLzR3Fm7c9jtvVgK4xctWzxnoqBXbH2NawRyY1unhbf+evxxqfzf37lewPOjPJnpTLvJyZCdV3ilLvW1vOV7qw1Cnyv3GnJ0dI9DUzXjxw+H4r8kAjnNr0gWyiTi23YXuPtb5o0c/1wdRcLmobutDbXXoLiltFRhEAwhP4OWOd+5X5MSmlmQAt8wr6233vq4ZSRdCe9Oo1MQQgO7XZH6qaA9dpkYBkdG+/93umT2ZjWlEYXk7ygNnCzdnnfrQWiuJJIkCbBZ2V9EdrgXsitvTcsncz+Gjswm9neMDV/ue88XnXZJd2gGLtKtePZ5L6yeSnpcpR+hGKteu5/GMqHv4Xi0tLbJYxUdHpLVPprQQR5iaFVxiJiID3xiysxElD+nHOulAQQeknJcgTgXU8cC6qvO5AjMcmgjVk9m0vZXGJ4A3LfWPSPsB6KI8dJqa1yjiWx+5OPaxPK3ogIthDmHdrDlP6GqKlptrjO6N5VEyMByFCMj0+4BOhGVNe2EwAECEbHH84yL+biCEc5X9U+u0lomi/eLFgEVluxMh2YbuITCM+O6QNNBGjb0Ow34ttJzLw00l7X+mpylF2jocM+kLP3ehNE5G3cpBZboMhX02lhYjRV/jim1zc6RM8T6rllst8uO6hW17Z1v/hruztSrh/gK/SZNfvMxMX/LrjGpQK1QUJnz7/er0xGAwGg8FgMBgMBoPBYDAYjL+A/wQYAOpBPtnxn830AAAAAElFTkSuQmCC",
  "$Meta": {
    "Type": "ActionTemplate"
  }
}

History

Page updated on Wednesday, February 28, 2018