Skip to content

azure-arm-template: get CustomScriptExtension output #21

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .github/workflows/create-azure-self-hosted-runners.yml
Original file line number Diff line number Diff line change
Expand Up @@ -149,10 +149,16 @@ jobs:
creds: ${{ secrets.AZURE_CREDENTIALS }}

- uses: azure/arm-deploy@v1
id: deploy-arm-template
with:
resourceGroupName: ${{ secrets.AZURE_RESOURCE_GROUP }}
template: ./azure-self-hosted-runners/azure-arm-template.json
parameters: ./azure-self-hosted-runners/azure-arm-template-example-parameters.json ${{ env.AZURE_ARM_PARAMETERS }}

- name: Show post-deployment script output
env:
CUSTOM_SCRIPT_OUTPUT: ${{ steps.deploy-arm-template.outputs.customScriptInstanceView }}
run: echo "$CUSTOM_SCRIPT_OUTPUT" | jq -r '.substatuses[0].message'

- name: Deallocate the VM for later use
if: env.DEALLOCATE_IMMEDIATELY == 'true'
Expand Down
50 changes: 26 additions & 24 deletions azure-self-hosted-runners/azure-arm-template.json
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,12 @@
"nicName": "[concat(parameters('virtualMachineName'), '-nic')]",
"vnetName": "[concat(parameters('virtualMachineName'), '-vnet')]",
"vnetId": "[resourceId(resourceGroup().name,'Microsoft.Network/virtualNetworks', concat(parameters('virtualMachineName'), '-vnet'))]",
"subnetRef": "[concat(variables('vnetId'), '/subnets/', parameters('subnetName'))]"
"subnetRef": "[concat(variables('vnetId'), '/subnets/', parameters('subnetName'))]",
"UriFileNamePieces": "[split(parameters('postDeploymentPsScriptUrl'), '/')]",
"firstFileNameString": "[variables('UriFileNamePieces')[sub(length(variables('UriFileNamePieces')), 1)]]",
"firstFileNameBreakString": "[split(variables('firstFileNameString'), '?')]",
"firstFileName": "[variables('firstFileNameBreakString')[0]]",
Comment on lines +112 to +115
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Taken directly from the original template we used earlier.

"postDeploymentScriptArguments": "[concat('-GitHubActionsRunnerToken ', parameters('githubActionsRunnerToken'), ' -GithubActionsRunnerRegistrationUrl ', parameters('githubActionsRunnerRegistrationUrl'), ' -GithubActionsRunnerName ', parameters('virtualMachineName'), ' -StopService ', parameters('stopService'), ' -GitHubActionsRunnerPath ', parameters('githubActionsRunnerPath'))]"
},
"resources": [
{
Expand Down Expand Up @@ -243,38 +248,35 @@
]
},
{
"name": "Microsoft.CustomScriptExtension",
"apiVersion": "2015-01-01",
"type": "Microsoft.Resources/deployments",
"type": "Microsoft.Compute/virtualMachines/extensions",
"apiVersion": "2020-12-01",
"name": "[concat(parameters('virtualMachineName'), '/CustomScriptExtension')]",
"dependsOn": [
"[resourceId('Microsoft.Compute/virtualMachines/', parameters('virtualMachineName'))]"
],
"location": "[parameters('location')]",
"properties": {
"mode": "incremental",
"templateLink": {
"uri": "https://catalogartifact.azureedge.net/publicartifacts/Microsoft.CustomScriptExtension-arm-2.0.57/MainTemplate.json"
"publisher": "Microsoft.Compute",
"type": "CustomScriptExtension",
"typeHandlerVersion": "1.9",
"autoUpgradeMinorVersion": true,
"settings": {
"fileUris": "[split(parameters('postDeploymentPsScriptUrl'), ' ')]"
},
"parameters": {
"fileUris": {
"value": "[parameters('postDeploymentPsScriptUrl')]"
},
"vmName": {
"value": "[parameters('virtualMachineName')]"
},
"location": {
"value": "[parameters('location')]"
},
"arguments": {
"value": "[concat('-GitHubActionsRunnerToken ', parameters('githubActionsRunnerToken'), ' -GithubActionsRunnerRegistrationUrl ', parameters('githubActionsRunnerRegistrationUrl'), ' -GithubActionsRunnerName ', parameters('virtualMachineName'), ' -StopService ', parameters('stopService'), ' -GitHubActionsRunnerPath ', parameters('githubActionsRunnerPath'))]"
}
"protectedSettings": {
"commandToExecute": "[concat('powershell -ExecutionPolicy Unrestricted -File ', variables('firstFileName'), ' ', variables('postDeploymentScriptArguments'))]"
}
},
"dependsOn": [
"[resourceId('Microsoft.Compute/virtualMachines/', parameters('virtualMachineName'))]"
]
}
}
],
"outputs": {
"adminUsername": {
"type": "string",
"value": "[parameters('adminUsername')]"
},
"customScriptInstanceView": {
"type": "object",
"value": "[reference(resourceId('Microsoft.Compute/virtualMachines/extensions', parameters('virtualMachineName'), 'CustomScriptExtension')).instanceView]"
}
}
}