New Website Deployment Per Pull Request

Hello,

I’m setting up a new environment at my company that uses Git, TeamCity, and Octopus for development and deployments.

Part of our workflow dictates that all changes go through a pull request workflow. I currently have TeamCity building every pull request and updating the build status in BitBucket Server.

What I’m looking for is a way to deploy a new website with octopus, likely using octopack, after each pull request is built. I’d like to do this in such a way that after the deployment the developer or other interested party can reach [PRNumber].[Domain].com and test/verify/validate the changes meet requirements.

I imagine this has to be possible using Octopus, but I haven’t quite figured it out yet.

Thanks!

Hi,

Thanks for reaching out. This is absolutely possible, and a pretty common scenario :slight_smile:

How do I create a website from the deployment process?

The “Deploy a Nuget Package” step has a built-in feature called “IIS Website and App pools” whose goal is to create/reconfigure a website in IIS, and then deploy the content of the NuGet package into the app root site (or a custom dir of your choice)

A new website will be created as long as the site name is different on each run.

How do I name my site [PRNumber].[Domain].com ?

Once you add the “IIS Website and App pool” feature to your step, plenty of fields will be added to the step to help configure the website (see attached screenshot). You’re gonna want to set variables for these fields, as your goal is to create a brand new website on each run. Make sure to use Prompt Variables, as these variables can be defined by the user before running the deployment.

How do I pass values to these Prompt Variables from my TeamCity build?

The TeamCity steps are nothing but a wrapper of our command line tool Octo.exe(more info). This tool has a parameter called --variable which helps you pass values to prompt variables from the command line. From your build configuration, you’re gonna have to add this parameter on the TeamCity Octopus step field Additional Command Line Arguments (see attached screenshot) and this will pass the value to the Octopus variable at deployment time.

The last step will be for you to figure out how to get the PRNumber and pass it to a TeamCity variable, to be able to use it on the Additional Command Line Arguments field.

Hope this rant makes sense and helps you :slight_smile:

Dalmiro

Thank you very much! As soon as I get some time I will be testing this for sure!

How are you all cleaning up after a PR deployment? If I deploy PR #15 and its approved and merged in, what goes back and cleans that up? Is there anything in OCTO? Or is everyone running their own scheduled jobs to clean things up?

Hi Dru,

Thanks for reaching out.

There’s nothing built into Octopus that will help you with that. I’d personally recommend you to create an Octopus Project called “Cleanup” with Powershell script steps to clean things up for you. That project could have a prompt variable, which value you could use during the deployment to delete everything that’s named in a certain way.

Once you have that, you could use Octo.exe to trigger a deployment of this “Cleanup” project once the PR gets merged in. I bet you could even map this to the github “merge” event.

Hope that helps giving you some ideas.

Regards,
Dalmiro