Custom deployment scripts (PreDeploy, Deploy, PostDeploy) using Azure webapps


I’m trying to create a Deploy.ps1 that takes care of copying the correct robots.txt or whatever static file and to clean the extra config files (e.g. Web.QA.config).

I’ve done this before using a custom PowerShell to copy the robots.txt and the “File System - Clean Configuration Transforms” community step template in the context of and IIS Website, but now I’m deploying to an Azure web app.

I looked the task log and apparently, this is the variable I need “CurrentDirectory”,
Is there any way to get the “CurrentDirectory” value, in my case “C:\Octopus\Work\20170320232602-8” to use it on a deploy.ps1?

How do you handle these situations in the context of Azure web apps?


Ok, I managed to get it working with the $PSScriptRoot variable.

If someone is interested in how to change static files and remove extra config files using Azure webapps, this is the script I end up using.

$pathToClean = $PSScriptRoot

Write-Host "Applying robots.$OctopusEnvironmentName.txt on environment: $OctopusEnvironmentName"
Copy-Item -Path "$pathToClean\Content\robots_txt\robots.$OctopusEnvironmentName.txt" -Destination "$pathToClean\robots.txt"

Write-Host "Cleaning Configuration Transform files from $pathToClean"
if (Test-Path $pathToClean) {
	Write-Host "Scanning directory $pathToClean"
	$regexFilter = "*.*.config"
	Write-Host "Filter $regexFilter"

	if ($pathToClean -eq "\" -or $pathToClean -eq "/") {
		throw "Cannot clean root directory"

	$filesToDelete = Get-ChildItem $pathToClean -Filter $regexFilter -Recurse | `
					 Where-Object {!$_.PsIsContainer -and ($_.Name -NotMatch "((?i)(^.*\.exe\.config$|.*\.dll\.config$)$)")}

	if (!$filesToDelete -or $filesToDelete.Count -eq 0) {
		Write-Warning "There were no files matching the criteria"
	} else {
		Write-Host "Deleting files"

		foreach ($file in $filesToDelete)
			Write-Host "Deleting file $($file.FullName)"
			Remove-Item $file.FullName -Force
} else {
	Write-Warning "Could not locate path: $pathToClean"

Hi Ale,

$PsScriptRoot is almost always the way to go, though I’m pretty sure only using .\ would work too.

Thanks for sharing your workaround in the end :slight_smile: