Adding Files at Deploy Time

Hello,

I’m looking at add some files to the package at deploy time. I don’t actually want to modify the original package since it’s environment specific. I’ve tried adding files to the InstallationDirectory in PreDeploy, but they don’t seem to get picked up and sent off with the package. The reason why I want to add it before we actually deploy is because we are deploying to a staging slot on an Azure Web App that has auto-swap enabled. So after the deploy command finishes we won’t be able to modify the deployed contents before it hits production. We would definitely prefer to keep auto-swap enabled as well if possible.

Please let me know if you need any more information. Thanks!

Steve

Hi Steve,

Thanks for getting in touch! Azure deployment slots are commonly mistaken as being equivalent to environments in Octopus, as they’ve been named staging and production. Deployment slots are designed for handling blue-green deployments, meaning both slots should be production-ready and have the exact same config. It reduces downtime by swapping which slot is being pointed to.

To approach environment-specific files and values, I would suggest a couple of alternatives which can automate this process and make it easier to manage, instead of adding files to the package at deployment time. These options can allow you to have only a single package which includes all of your environment-specific files, while using different config and values per environment.

To change which environment-specific config files are used when deploying to different environments, you can use the configuration transformations feature in your package step. For example, you can transform your Web.config file to Web.Production.config when deploying to your production environment by adding Web.Production.config => Web.config in the additional transforms section. You can read more about it and refer to an example in our blog post: https://octopus.com/docs/deploying-applications/configuration-files

You can also substitute environment-specific values in your files. This is done using the substitute variables in files feature in your package step. Using scoped Octopus variables, you can direct which variable values are used in which environment. This is done by adding your variable name into the file’s value (where you want it to be substituted) using the syntax #{VariableName}. During your deployments, that will change to the value of the Octopus variable that is scoped to the environment that you’re deploying to. You can refer to our documentation about this feature as well: https://octopus.com/docs/deploying-applications/substitute-variables-in-files

Let me know what you think of these options, or if I’ve misunderstood anything about your scenario :slight_smile:

Best regards,

Kenny

Hi Kenny,

Thanks for the detailed response! I’m not looking to have different configs from staging and production. I only brought up the staging slot because in Azure Web Apps, there is the ability to set auto-swap. This basically makes the staging slot the old production slot and the production slot the new staging slot. I’m sure they do it with routing in the background, but the main consequence of that is after I deploy to the staging slot, I will not have access to what I just deployed, because it will have moved its contents to the production slot.

We have looked at your configuration transformations and it may be something we’ll use, but right now we pull our configs from a separate source and build up configuration files. It’s also possible that we may want to add other non-config files that are environment specific.

So while I appreciate the workarounds, I just want to know if it’s possible to add a file at deploy time. Is that something we can do?

Thanks for your time,
Steve

Hi Steve,

Thanks for following up, and no problem for the details! I’m sorry about the delay in getting back to you, and not directly answering your initial question. You can add files at deployment time, though deploying things that were not in the package initially isn’t something we generally recommend, as we believe it’s best practice to ensure all necessary files are packaged.

You can use the Copy-Item PowerShell command in your pre-deployment script to copy a file from your server to the deployment destination. As an example, a simple pre-deployment script would look like Copy-Item -Path C:\path\new.config to specify the file to copy.

I hope that helps! Let me know if you have any further questions.

Best regards,

Kenny

Hello Kenny,

Thanks again for the response! Sorry I was so insistent, but we’re rapidly trying to prove technical viability with some of our current processes. I suppose it would probably be something different than Copy-Item for Azure Web Apps. Maybe something like this? http://help.octopusdeploy.com/discussions/problems/44863-deploying-file-to-azure-web-app-site-folder

Either way, that answers my question. I appreciate your time!

Thanks,
Steve

Hey Steve,

That’s not a problem at all - I’m just sorry about the time it took me to get back to you! Let me know if you have any issues with the solution from the link you provided, or have any other questions at all. :slight_smile:

Best regards,

Kenny