Find previous deployment path

Hello

During a new release I’d like to copy app_offline.htm file to the currently active deployment folder. This will take my app offline while the new version is deployed.

However i don’t seem to be able to find the previous deployment path.
i tried using Octopus.Release.CurrentForEnvironment.Number but that doesn’t match the folder name.

Is there a way to find the previous deployment path for a web application?

Thank you.

Fabian

Hi Fabian,

Thanks for getting in touch! I believe you’re after either of these system variables:

Octopus.Tentacle.PreviousInstallation.OriginalInstalledPath which is the directory the previous package version was extracted to. Or if you’re using the custom installation directory feature, you could use Octopus.Tentacle.PreviousInstallation.CustomInstallationDirectory.

Do either of these give you the result you’re after? Let me know how you go or if you have any further questions moving forward. :slight_smile:

Best regards,

Kenny

Hi Kenny

That didn’t work because this is not the folder I am looking for.

Copy-Item : Could not find a part of the path 'C:\Octopus\Work\20180912161703-2

September 12th 2018 09:17:05

Error

4534-119#{Octopus.Tentacle.PreviousInstallation.OriginalInstalledPath}\app_off

September 12th 2018 09:17:05

Error

line.htm’.

I am looking for the path where the IIS web site is pointing to. i.e. the folder where the files are deployed to not where the nuget is extracted to.

So I am looking for this folder D:\Octopus\Applications\DEV\ADBrowser\1.1.20180911.01_2 which is the folder the IIS web site is pointing to.

How can I get this folder inside of my deployment step?

Thank you.

Fabian

8-6325

Hi Fabian,

Thanks for following up, and I’m sorry to hear that didn’t work for you. It looks like the variable strangely isn’t evaluating for some reason. May I ask for a copy for the script you’ve written to copy the item to the new directory, and your verbose deployment logs from a failed deployment? The following doc page outlines how you can produce and export this log, and I’ll be happy to look more in depth at this to help determine what’s causing this incorrect behavior.

I look forward to hearing back and getting to the bottom of this one!

Best regards,

Kenny

Here is my powershell script

$targetInstallationFolder = $OctopusParameters[“InstallationFolder”].replace("+","_")

$sourceOfflineHtml = Join-Path $OctopusParameters[“AppOfflineFolder”] $OctopusParameters[“AppOfflineFileName”]

$targetOfflineHtml = Join-Path $targetInstallationFolder $OctopusParameters[“AppOfflineFileName”]

#Copy offline file to folder that is currently pointing to the active web application

if (Test-Path($sourceOfflineHtml))

{

    Copy-Item $sourceOfflineHtml $targetOfflineHtml

}

Logs are attached.

Thank you.

Fabian

8-6325

ADBrowserServerTasks-24593.log.txt (91.3 KB)

Hi Fabian,

Thanks for following up and confirming those details. I’ve been able to reproduce this error when running this script as a script step before deploying the package, however I’m not hitting this when I embed the script as a deployment script in the package step. Does doing this fix the issue for you?

If it doesn’t fix it, could you confirm some additional details to ensure I’m understanding and testing this properly? Your $sourceOfflineHtml variable is composed of essentially #{AppOfflineFolder}\#{AppOfflineFileName} when resolves to D:\Octopus\OfflinePages\app_offline.htm. This is the source folder where your app_offline.htm file resides, and you’re wanting to copy it to the previous installation folder. Is that correct?

I look forward to hearing back!

Best regards,

Kenny

Hi Kenny

Did you have a chance to look at the logs?

I forgot to mention that the InstallationFolder parameter is set to #{Octopus.Tentacle.PreviousInstallation.OriginalInstalledPath}

The AppOfflineFolder is set to D:\Octopus\OfflinePages

The AppOfflineFileName is set to app_offline.htm

Hi Fabian,

Thanks for following up! I’ve looked through your logs and it looks like this script is being run as a standalone script step, and when running it this way I’ve replicated this behavior. However I avoid this when I’ve configured it to run as a custom postdeploy script in the package step. This is because the Octopus.Tentacle.PreviousInstallation.OriginalInstalledPath variable is only available during the execution of the package step itself. Have you been able to achieve this by embedding it into your package step, as shown in the following documentation?

I hope this helps! Let me know how you go or if you have any further questions. :slight_smile:

Best regards,

Kenny

Hi Kenny
Sorry for not replying properly. I don’t get notification via my email when you replied. Not sure why. So i just saw your posts.
I have found a solution as how to find the folder where the iis web app is pointing to.

I’m including my powershell script.

Basically i’m going directly it IIS to find the folder instead of using octopus variables.

#Copies a file from a folder to app_offline.htm in the current folder for a web application
#Note that we do not need to delete this file to bring the app online
#because octopus creates a brand new folder structure where the app_offline.htm will NOT be present

#you only need to delete the app_offline.htm file in the old folder
#if you need to rollback to that previous version of your web application

#Get Octopus Parameters
$Site = $OctopusParameters[“SiteName”]
$WebApplication = $OctopusParameters[“WebApplicationName”]
$AppOfflineFileName = $OctopusParameters[“AppOfflineFileName”]
$AppOfflineFolder = $OctopusParameters[“AppOfflineFolder”]

if (!(Test-Path $AppOfflineFolder)) {
throw “Error: Could not find application offline file folder $($AppOfflineFolder)”
}

Import-Module WebAdministration

#build path to file that should be copied to app_offiline.htm in target folder
$sourceOfflineHtml = Join-Path $AppOfflineFolder $AppOfflineFileName
if (!(Test-Path $sourceOfflineHtml)) {
throw “Error: Could not find application offline file $($sourceOfflineHtml)”
}

#build target folder and file name
$targetInstallationFolder = (Get-WebApplication -Site $SiteName -Name $WebApplicationName).PhysicalPath + “”
$targetOfflineHtml = Join-Path $targetInstallationFolder “App_Offline.htm”

#Copy offline file to folder that is currently pointing to the active web application
Copy-Item $sourceOfflineHtml $targetOfflineHtml
Write-Output “Copied $($sourceOfflineHtml) to $($targetOfflineHtml)”

Hi Fabian,

Thanks for following up, and no need to apologize. :slight_smile:

That’s great to hear you’ve found a solution, and I appreciate you sharing it here for everyone to see - I’m sure it’ll come in handy to someone looking to do the same thing. Please don’t hesitate to reach out if you have any further questions or concerns in the future!

Best regards,

Kenny

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