Modules/Publish-OctoDeployment.psm1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
function Publish-OctoDeployment {
    [CmdletBinding()]
    param (
        [Parameter(Mandatory=$true, Position=0)]
        [string]$version,
        [Parameter(Mandatory=$false, Position=1)]
        [string]$environmentName = "INT" 
    )
    $repository = Get-OctoRepository
    $environment = $repository.Environments.FindByName($environmentName)

    $toDeploy = $repository.Releases.FindOne({ param($r) $r.Version -eq $version }) 
    if ($toDeploy -eq $null) { throw "No release found with version '$version'" }

    $deployment = [Octopus.Client.Model.DeploymentResource]::new()
    $deployment.ReleaseId = $toDeploy.Id
    $deployment.ProjectId = $toDeploy.ProjectId
    $deployment.EnvironmentId = $environment.Id
    
    $repository.Deployments.Create($deployment)
}