Skip to content

Instantly share code, notes, and snippets.

@renzors
renzors / RetryLogic.ps1
Created March 8, 2019 16:59
PS script to retry
$retries = 3 #$OctopusParameters['appPoolCheckRetries']
$delay = 1000 #$OctopusParameters['appPoolCheckDelay']
$counter = 1
do {
try {
#Script Here
Break
} catch {
Write-Error $_.Exception.InnerException.Message -ErrorAction Continue
Write-Host "Attemp $counter failed."
@renzors
renzors / webapptemplate.json
Last active January 7, 2019 21:30
This template has an Appservice plan + App Insights + Webapp (with app inshights extension and hybrid connection) + Slot (with app inshights extension and hybrid connection)
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"appServiceName": {
"type": "string",
"minLength": 1
},
"webAppName": {
"type": "string",
$serviceAppUrl = $OctopusParameters["Stemp.LoginAppUrl"]
$servicePassword = $OctopusParameters["Stemp.LoginPassword"]
$serviceTenantId = $OctopusParameters["Stemp.LoginTenantID"]
$serviceSubscriptionId = $OctopusParameters["Stemp.LoginSubscriptionID"]
$cosmosResourceGroupName = $OctopusParameters["Stemp.CosmosResourceGroup"]
$cosmosName = $OctopusParameters["Stemp.CosmosName"]
$cosmosDatabaseName = $OctopusParameters["Stemp.CosmosDataBaseName"]
$cosmosCollectionName = $OctopusParameters["Stemp.CosmosCollectionName"]
# Login with Service Principal
#Login-AzureRmAccount
#Set-AzureRmContext -SubscriptionName ""
$resourceGroupName = ""
$webAppName = ""
$functionName = "Authenticate"
$variableName = "masterKey"
function Get-PublishingProfileCredentials($resourceGroupName, $webAppName){
$resourceType = "Microsoft.Web/sites/config"
# Helper Funtions
function CatalogFolderDropContent($catalog, $folderName)
{
if($catalog.Folders[$folderName] -eq $null){
return;
}
while ($catalog.Folders[$folderName].Environments.Count -ne "0")
{
$env = $catalog.Folders[$folderName].Environments | Select-Object -First 1
$resourcegroupname = "bsk-ml-eastus-rgroup-ops-01"
$allwebapps = "bsk-ml-eastus-api-webapp-ops-01, bsk-ml-eastus-audioextractor-webapp-ops-01"
$insightname = "bsk-ml-eastus-insights-ops-01"
#Removing Tags
$insight = Get-AzureRmResource -ResourceName $insightname -ResourceGroupName $resourcegroupname
$insight.tags = @{}
Set-AzureRmResource -Tag $insight.Tags -ResourceId $insight.ResourceId -Force
#Getting Resource Group ID
$insight = Get-AzureRmResource -ResourceName #{LOCAL.AppInsights} -ResourceGroupName #{LOCAL.ResourceGroupName}
$webapp = Get-AzureRmResource -ResourceName #{LOCAL.WebAppName} -ResourceGroupName #{LOCAL.ResourceGroupName}
$webappid = $webapp.ResourceId
$insight.tags += @{"hidden-link:$webappid"="Resource"}
Set-AzureRmResource -Tag $insight.Tags -ResourceId $insight.ResourceId -Force
# Clean old files
del composer_update_*.txt
# Start composer (we just let it timeout and redirect output and exit code to files)
composer update 1> composer_update_output.txt 2> composer_update_error.txt & echo %errorLevel% > composer_update_exitcode.txt
# Then we actively wait until exitcode file exist as a flag on execution end
if exist composer_update_exitcode.txt (echo exit) else (echo still running)
# Then we get the data from files
#Setting up variables of our WebApp
$AzureWebSite = "MySite"
$SourceSlot = "staging"
$DestinationSlot = "production"
$AzureResourceGroup = "MyResourceGroup"
#Swapping
Switch-AzureRmWebAppSlot -SourceSlotName $SourceSlot -DestinationSlotName $DestinationSlot -ResourceGroupName $AzureResourceGroup -Name $AzureWebSite
#Getting Hybrid Connections from staging slot
@renzors
renzors / ChangeDeploymentPath.ps1
Created November 3, 2017 21:50
Allow set a new deployment path before and after of a deployment
#Add-AzureRmAccount
#Get-AzureRmSubscription
#Set-AzureRmContext -SubscriptionName ""
$AzureWebSite = ""
$AzureResourceGroup = ""
$Resource = Get-AzureRmResource -ResourceType "microsoft.web/sites/config" -ResourceGroupName $AzureResourceGroup -ResourceName $AzureWebSite/web -ApiVersion "2016-08-01"
$Resource.Properties.virtualApplications[0].physicalPath = "site\wwwroot\"
$Resource | Set-AzureRmResource -Force -ApiVersion "2016-08-01"