是的,您可以在自定义构建/发布步骤/任务中获取相关信息(例如Tenant Id)。
有关构建扩展的更多信息,请参阅:Add a build task。
如果您不知道如何实现它,可以参考以下步骤获取Azure PowerShell的所有源代码步骤/任务。
- 建立一个内部部署生成代理:Deploy an agent on Windows
- 创建一个构建/发布定义
- 添加Azure中的PowerShell步/任务和配置它
- 队列此版本/释放
- 登录您的构建代理机器,检查Azure PowerShell的步骤/任务
[agent folder]\tasks\AzurePowerShell
简单的构建/释放步骤/ tas ķ扩展:
文件:
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代码:在task.json
$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
部分代码(输入框,选择订阅):
"inputs": [
{
"name": "ConnectedServiceName",
"type": "connectedService:AzureRM",
"label": "Azure RM Subscription",
"defaultValue": "",
"required": true,
"helpMarkDown": "Select the Azure Resource Manager subscription for the deployment."
},
....
感谢。这是否意味着通过Powershell获得连接细节的唯一方法是?我想知道我们是否可以通过.NET代码获得它? –
@IsaacAbraham它使用vsts-task-lib来获取端点,它是powershell代码,但您可以从.net代码中调用powershell脚本。 –