Last active
January 9, 2020 21:24
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 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" |
Author
Author
Updated with proper resource names from the tutorial
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
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