Different files for different environments


is there a way i can add files in my project that are only intended to be deployed in specific environments?
For example a robots.production.txt that allows robots, and a robots.staging.txt that disallows robots. These files when deployed should be renamed to robots.txt.

The other option i guess would be to create a separate nuspec to contain separate files (And have different automated builds etc). Seems complicated.

The first approach resembles the web.config transformations… except that nothing is transformed, only “filtered” for deployment in specific environment.

thanks in advance

You could add something in your post deploy.ps1 to cleanup or leave the file(s) in place based on the octopus environment variable. It knows what environment you are deploying to then you could “switch” the cleanup/leave based on that variable.

I am using this Deploy.ps1, it also remove “unused” web.config transsformation files…

# use these for test:
#$envirement = "Production"
#$installDir = $PSScriptRoot

$installDir = $OctopusParameters["Octopus.Action.Package.CustomInstallationDirectory"]
$envirement = $OctopusParameters["Octopus.Environment.Name"]

$robotsTxtToUse = join-path $installDir ("robots." + $envirement + ".txt")
$robotsTxtTarget = join-path $installDir "robots.txt"

if(Test-Path $robotsTxtToUse){
	Copy-Item $robotsTxtToUse $robotsTxtTarget -Force
    Write-Output ("Content updated for: "+ $robotsTxtTarget + " with " + $robotsTxtToUse + " as content source")
   Write-Output ("Content not updated for: " + $robotsTxtTarget + ". Did not find: " + $robotsTxtToUse + " to use as content source")

Get-ChildItem $installDir -Filter "robots.*.txt" | ForEach-Object {
    Write-Output ("Deletes: " + $_.FullName)
    Remove-Item $_.FullName

Get-ChildItem $installDir -Filter "web.*.config" | ForEach-Object {
    Write-Output ("Deletes: " + $_.FullName)
    Remove-Item $_.FullName

While trying to get this PowerShell running - it doesn’t find anything for the variable $installDir

Therefore not gets run.

For an Azure WebApp, what would be the settings for:
Run On Deployment Target / Octopus Server
Target Roles - ?

Any ideas why its not running?



@andy the $installDir = $OctopusParameters[“Octopus.Action.Package.CustomInstallationDirectory”]
requires you to customize the right hand side between the square brackets. This variable gets created based on your actual job config, so it might be slightly different if you called your steps or variables something different.

Our apologies for not jumping onto this ticket sooner but it appears to have slipped through the cracks.
Are you still having problems with this issue regarding managing files for different environments through the deployment process? Hopefully you have seen that you can write the post-deployment scripts to keep & rename the file you want, and remove any others. If you have any further questions please feel free to get back to us, ideally by lodging a new ticket to reduce the amount of noise to everyone else in this message chain.
Thanks again,