Skip to content

Instantly share code, notes, and snippets.

@DamianStanger
Created December 11, 2015 17:17
Show Gist options
  • Save DamianStanger/13f4678cd791c0224623 to your computer and use it in GitHub Desktop.
Save DamianStanger/13f4678cd791c0224623 to your computer and use it in GitHub Desktop.
Powershell script that uses msdeploy to deploy the current directory contents to azure websites.
param(
[string]$WEBSITE_NAME ='WEBSITE_NAME',
[string]$PUBLISH_PROFILE_URL ='https://xxx-staging.scm.azurewebsites.net:443',
[string]$PUBLISH_PROFILE_USERNAME='$yyy__staging',
[string]$PUBLISH_PROFILE_PASSWORD='zzz'
)
Write-Host -ForegroundColor Cyan "------------------------------------------------------"
Write-Host -ForegroundColor Cyan "WEBSITE_NAME: $WEBSITE_NAME"
Write-Host -ForegroundColor Cyan "PUBLISH_PROFILE_URL: $PUBLISH_PROFILE_URL"
Write-Host -ForegroundColor Cyan "PUBLISH_PROFILE_USERNAME: $PUBLISH_PROFILE_USERNAME"
Write-Host -ForegroundColor Cyan "PUBLISH_PROFILE_PASSWORD: $PUBLISH_PROFILE_PASSWORD"
$contentPath = (Get-Location).Path
Write-Host -ForegroundColor Cyan "contentPath: $contentPath"
$computerName = "$PUBLISH_PROFILE_URL/msdeploy.axd?site=$WEBSITE_NAME"
Write-Host -ForegroundColor Cyan "computerName: $computerName"
$cmd = 'msdeploy -verb:sync -source:contentPath="'+$contentPath+'" -dest:contentPath="'+$WEBSITE_NAME+'",ComputerName="'+$computerName+'",UserName="'+$PUBLISH_PROFILE_USERNAME+'",Password="'+$PUBLISH_PROFILE_PASSWORD+'",AuthType="Basic"'
Write-Host -ForegroundColor Cyan "cmd /c $cmd"
try{
cmd /c $cmd
if($LASTEXITCODE -ne 0){
Write-Host -ForegroundColor Yellow "LASTEXITCODE: $LASTEXITCODE -ne 0 : An Error occured..."
Exit $LASTEXITCODE
}
}
catch{
Write-Host -ForegroundColor Yellow "----- Error -----"
Write-Host -ForegroundColor Yellow 'Error:' $Error
Write-Host -ForegroundColor Yellow '$_: ' $_
Write-Host -ForegroundColor Yellow 'Exit 1'
Exit 1
}
write-host -ForegroundColor Cyan "FIN!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment