Yes, you can get the related information (e.g. Tenant Id) in a custom build/release step/task.
More information about build extension, you can refer to: Add a build task.
If you don’t know how to achieve it, you can refer to these steps to get all source code of Azure PowerShell step/task.
- Set up a on premise build agent: Deploy an agent on Windows
- Create a build/release definition
- Add Azure PowerShell step/task and config it
- Queue this build/release
- Log on your build agent machine, check the Azure PowerShell step/task in
[agent folder]\tasks\AzurePowerShell
The simple build/release step/task extension:
Files:
AzureCustomTask
Ps_modules (can be found in the Azure PowerShell step/task folder, refer to previous steps)
Test.ps1
Icon.png
Task.json
Test.ps1 code:
$serviceNameInput = Get-VstsInput -Name ConnectedServiceNameSelector -Default 'ConnectedServiceName'
Write-Host $serviceNameInput
$serviceName = Get-VstsInput -Name $serviceNameInput -Default (Get-VstsInput -Name DeploymentEnvironmentName)
Write-Host $serviceName
if (!$serviceName) {
# Let the task SDK throw an error message if the input isn't defined.
Get-VstsInput -Name $serviceNameInput -Require
}
$endpoint = Get-VstsEndpoint -Name $serviceName -Require
Write-Host $endpoint.Auth.Parameters.TenantId
Part code in task.json (input box to select subscription):
"inputs": [
{
"name": "ConnectedServiceName",
"type": "connectedService:AzureRM",
"label": "Azure RM Subscription",
"defaultValue": "",
"required": true,
"helpMarkDown": "Select the Azure Resource Manager subscription for the deployment."
},
....