Skip to content

Instantly share code, notes, and snippets.

@Fleid
Last active January 9, 2020 21:25
Show Gist options
  • Save Fleid/03567f6dc7e76d632ceb58c8ab667578 to your computer and use it in GitHub Desktop.
Save Fleid/03567f6dc7e76d632ceb58c8ab667578 to your computer and use it in GitHub Desktop.
PowerShell Core script to deploy an Azure Stream Analytics job in a release pipeline of Azure DevOps Pipelines
# Step 1: map arguments
write-host "101 - Mapping arguments"
$sourceProjectName = "ASATest1"
$targetResourceGroup = ${ENV:VG-RESOURCEGROUP}
$stagingDirectory = "$ENV:SYSTEM_ARTIFACTSDIRECTORY\$ENV:RELEASE_PRIMARYARTIFACTSOURCEALIAS\drop"
$templatePath = "$stagingDirectory\$sourceProjectName.JobTemplate.json"
$validationParametersPath = "$stagingDirectory\$sourceProjectName.JobTemplate.parameters.json"
$finalParametersPath = "$stagingDirectory\$sourceProjectName.JobTemplate.parameters.final.json"
$vaultName = "fleideKV"
$liveInputIoTHub1key = (Get-AzKeyVaultSecret -VaultName $vaultName -Name "kvinputIoTHub1key").SecretValueText
$liveOutputBlobStorage1key = (Get-AzKeyVaultSecret -VaultName $vaultName -Name "kvoutputBlobStorage1key").SecretValueText
# Step 2 : Update parameters with live values
write-host "201 - Inserting live parameters"
$parametersData = Get-Content $validationParametersPath | ConvertFrom-Json
$parametersData.parameters.Input_IoTHub1_sharedAccessPolicyKey.value = $liveInputIoTHub1key
$parametersData.parameters.Output_BlobStorage1_Storage1_accountKey.value = $liveOutputBlobStorage1key
$parametersData.parameters.StreamAnalyticsJobName.value = "${ENV:VG-ASAJOBNAME}"
$parametersData.parameters.Location.value = "${ENV:VG-LOCATION}"
$parametersData.parameters.OutputStartMode.value = "${ENV:VG-OUTPUTSTARTMODE}"
write-host "202 - Generating validation parameter file"
$parametersData | ConvertTo-Json | Out-File $finalParametersPath
# Step 3: execute the deployment
write-host "301 - Executing Incremental ARM RG Deployment"
New-AzResourceGroupDeployment `
-ResourceGroupName $targetResourceGroup `
-TemplateFile $templatePath `
-TemplateParameterFile $finalParametersPath `
-Mode Incremental
# Step 9 : Done
write-host "999 - All done"
@Fleid
Copy link
Author

Fleid commented Jan 8, 2020

@Fleid
Copy link
Author

Fleid commented Jan 9, 2020

Moved variable declaration to the top

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment