IIS web app - Only allow maste branch to de deployed to PROD

I am coming from a Azure Devops background and hence Octopus is relatively new to me.

Background

  • Source control is BitBucket
  • CI is Jenkins
  • Application is .NET Web App package
  • Jenkis is pushing the package and also pushing the SCM Build Information to Octopus.

No problem so far.

Octopus lifecycle

Octopus is lifecycle is configured as follows:
DEV β†’ UAT β†’ PROD

DEV

Can have any feature branch deployed

UAT

Only allow master branch.

PROD

Only allow master branch.

Current solution

I have achieved this via a custom PowerShell script task.

$Pbi=$Octopus["Octopus.Deployment.PackageBuildInformation"]
$JsonPbi = $Pbi | ConvertFrom-Json
$Branch = $JsonPbi.Branch

if ("master" -ne $Branch)
{
    Write-Error -Message "Only master branch is allowed"
}

Question to Octopus team

Is there a better alternative?

Thank you,
Sau

Hi Sau,

Welcome to the Octopus Deploy Community! Thanks for reaching out about your current branch solution.

To gain more control over what branch is deployed to specific environments, I would recommend the use of Channels and Version Rules within your project. This will allow you the ability to deploy a feature release to your DEV environment while deploying the master to UAT or PROD.

This doc on Channels and implementing Channel Version Rules should help you to achieve the desired solution by selecting the correct versions of packages for the Channel, therefore deploying to the correct Environment.

I hope this helps guide you in the right direction. If you have any further questions about the above please don’t hesitate to let us know.

Happy Deployments!

Kind regards,
Lauren

Hi @Lauren.Cagney ,
Yes - Channels and Version rules makes more sense. I had my suspicions about my scripted appproach .

Thank you.

2 Likes