Deploy/Promote an existing release in a specific environment to another specific environment

Hi,
I would like to deploy an existing release from one selected environment to another environment.
I deploy the release in Beta to prod Approval, only after this release approved I need to deploy that release from
Beta -> Demo
ProdApproval -> Prod

Based on my research, I know that I should provide Project id, deployment id, environment id and release id.
But how can I get the release-id from Beta abd ProdApproval environements only to promote them to Demo and Prod respectively.

Can someone suggest me a solution how to achieve this.

Hi,

The solution is to use Channels, with channels you can have different lifecycles per channel.
Have a read of the documentation page I linked before, it should explain everything.
And if you still unclear on anything let us know :slight_smile:

Regards
John

Thanks for your reply John, can you please elaborate the idea little bit more as I am new to Octopus Deploy and just started using Octopus Rest API.

We are planning to promote releases for multiple projects (4 projects) at a time.

Hi,

From what I gather from your initial question it seems you have different branch strategies, eg you may want to release your software to only a subset of people (the Beta group) and then you also have your Production branch.
With Channels, you can build your pipeline in such a way that you model exactly these distinct groups.

Can you expand more on your release pipeline, so I understand it a bit more?

Also, we have this documentation page that goes into more detail, hopefully, this doc will clarify a few more things?

Regards
John

Hi John,

I referred your github page for this task, and used CreateReleaseAndDeployment.ps1 code.

I provided the source and destination environments to promote a release from source to destination environments respectively.

But I would like to check if that version already exists or not before I deploy. is there any way to check this?

Hi Amulya,

You can check whether a release has been deployed to an environment by making the following API call. The EnvironmentId property on the Deployment resource is what you are looking for.

Please, let me know if this doesn’t solve your problem.

Regards,

Pawel

1 Like

Thanks Pawel, it worked.

For my next step, I need to make it scheduled deployment, I’m planning to do it using Windows Task Scheduler.

Is it possible using Rest API.

Scheduled deploys via API I found this issue opened few years ago but it was closed.

This is my code to promote deployments from Mirror to Beta.

$apiKey = “API-XXX”
$Header = @{ “X-Octopus-ApiKey” = $apiKey }
$OctopusURL = “https://deploy.abc.com#Octopus URL
$ProjectsSlugs = @(“test”);
$DestEnvironmentName = “Beta” #Destination Env
$SourceEnvironmentName = “Mirror” #Source Env

foreach($ProjectSlugName in $ProjectsSlugs){
echo $ProjectSlugName

$Environments = Invoke-WebRequest -Uri "https://deploy.cambridgefx.com/api/Environments/all" -UseBasicParsing  -Headers $Header | ConvertFrom-Json
$Project = Invoke-WebRequest -Uri "https://deploy.cambridgefx.com/api/projects/$ProjectSlugName" -UseBasicParsing -Headers $Header| ConvertFrom-Json

$DestEnvironment = $Environments | ?{$_.name -eq $DestEnvironmentName}
$SourceEnvironment = $Environments | ?{$_.name -eq $SourceEnvironmentName}

$ProjectId = $Project.Id
$DestEnvId = $DestEnvironment.Id
$SourceEnvId = $SourceEnvironment.Id

$DeploymentData = Invoke-WebRequest -Uri "https://deploy.cambridgefx.com/api/deployments?environments=$SourceEnvId&projects=$ProjectId&taskState=Success" -UseBasicParsing -Headers $Header | ConvertFrom-Json
$ReleaseId = $DeploymentData.Items.ReleaseId | select -uniq
echo $Project.Name $ProjectId 
echo "Destination: "$DestEnvironment.Name $DestEnvId 
echo "Source: "$SourceEnvironment.Name $SourceEnvId 
echo $ReleaseId

if (-not ([string]::IsNullOrEmpty($ReleaseId)))
{
    echo "Release exists in source environment"
    $checkRelease = Invoke-WebRequest -Uri "https://deploy.cambridgefx.com/api/releases/$ReleaseId/deployments" -UseBasicParsing -Headers $Header | ConvertFrom-Json
    $checkReleaseExists = $checkRelease.Items.EnvironmentId | select -uniq

    if($checkReleaseExists.Contains($DestEnvId)){
        echo "Error: Release already exists in" $DestEnvironment.Name
    }else{
        echo "Create a release; Release doesn't exists in "$DestEnvironment.Name
        $DeploymentBody = @{ 
                ReleaseID = $ReleaseId
                EnvironmentID = $DestEnvId 
              } | ConvertTo-Json
        
        $ReleaseProject = Invoke-WebRequest -Uri https://deploy.cambridgefx.com/api/deployments -UseBasicParsing -Method Post -Headers $Header -Body $DeploymentBody
    }
}else{
    echo "Release doesn't exists in source environment"
}

}

Hi Amulya,

The issue was closed because we implemented the feature. Have a look at deployAt parameter in both DeployRelease and CreateRelease commands.

Let me know you go.

Regards,

Pawel

Thanks Pawel,
It worked fine, promote-release does the exact job for me.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.