Skip to content

Instantly share code, notes, and snippets.

@Fleid
Last active January 9, 2020 21:24
Show Gist options
  • Select an option

  • Save Fleid/10ca674ef4335234c7aa9ec3a06f0deb to your computer and use it in GitHub Desktop.

Select an option

Save Fleid/10ca674ef4335234c7aa9ec3a06f0deb to your computer and use it in GitHub Desktop.
PowerShell Core script to build an Azure Stream Analytics job in Azure DevOps Pipelines
# Step 0: map arguments and variables
$sourceProjectName = "ASATest1"
$targetResourceGroup = ${ENV:VG-RESOURCEGROUP}
$sourceDirectory = $ENV:BUILD_SOURCESDIRECTORY
$stagingDirectory = $ENV:BUILD_ARTIFACTSTAGINGDIRECTORY
$scriptPath = "$sourceDirectory\$sourceProjectName.asaql"
$templatePath = "$stagingDirectory\$sourceProjectName.JobTemplate.json"
$generatedParametersPath = "$stagingDirectory\$sourceProjectName.JobTemplate.parameters.json"
$validationParametersPath = "$stagingDirectory\$sourceProjectName.JobTemplate.parameters.validation.json"
# Step 1: generate ARM template files
## First, install the required package
write-host "101 - Installing azure-streamanalytics-cicd package"
npm install -g azure-streamanalytics-cicd
## Then, generates the templates from source
write-host "102 - Compiling script to ARM templates"
azure-streamanalytics-cicd build -scriptPath $scriptPath -outputPath $stagingDirectory
# Step 2: update the files to remove null credentials
write-host "201 - Inserting ValidationOnly credentials"
$parametersData = Get-Content $generatedParametersPath | ConvertFrom-Json
#Hardcoded parameters, this can be scripted instead but not sure of the ROI yet
$parametersData.parameters.Input_IoTHub1_sharedAccessPolicyKey.value = "ValidationOnly"
$parametersData.parameters.Output_BlobStorage1_Storage1_accountKey.value = "ValidationOnly"
write-host "202 - Generating validation parameter file"
$parametersData | ConvertTo-Json | Out-File $validationParametersPath
# Step 3: test the deployment
write-host "301 - Testing ARM Deployment"
$testResult = Test-AzResourceGroupDeployment `
-ResourceGroupName $targetResourceGroup `
-TemplateFile $templatePath `
-TemplateParameterFile $validationParametersPath `
-Mode Incremental
if ($testResult) {throw($testResult.Message)}
# Step 4: move files to staging folder
write-host "402 - Moving release script to Staging Dir"
Move-item "$sourceDirectory\deploy\release.ps1" $stagingDirectory
# Step 9 : done
write-host "999 - All done"
@Fleid

Fleid commented Jan 2, 2020

Copy link
Copy Markdown
Author

Walk-through, leverages the ASA CI/CD npm package
A lot is hardcoded and must be adapted (project name, credential parameters..._
Requires the following variable (ideally from a variable group - defined in the Library): VG-RG-STAGING : target resource group name for validation

@Fleid

Fleid commented Jan 8, 2020

Copy link
Copy Markdown
Author

Updated with proper resource names from the tutorial

@Fleid

Fleid commented Jan 9, 2020

Copy link
Copy Markdown
Author

Moved variable declaration to the top

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