虽然我们能够在 VSTS 中使用 Powershell Azure 任务进行发布,但有时我们也会运行 F# 脚本进行发布,作为其中的一部分,我们希望使用服务主体将 Assets 部署到 Azure。我们已经在 VSTS 中注册了 SP,Powershell 可以访问它 - 但是有没有办法,例如原始命令行等来获取租户 ID 等,以便我们可以手动使用它们?例如作为环境变量?
我们唯一的其他选择是手动将租户 ID 等作为构建变量复制到版本中,但这对我来说似乎是一个解决方法。
最佳答案
是的,您可以在自定义构建/发布步骤/任务中获取相关信息(例如租户 ID)。
更多关于构建扩展的信息,您可以引用:Add a build task .
如果您不知道如何实现,可以引用这些步骤来获取Azure PowerShell步骤/任务的所有源代码。
- 设置本地构建代理:Deploy an agent on Windows
- 创建构建/发布定义
- 添加 Azure PowerShell 步骤/任务并进行配置
- 将此构建/发布排队
- 登录构建代理计算机,检查
[代理文件夹]\tasks\AzurePowerShell
中的 Azure PowerShell 步骤/任务
简单的构建/发布步骤/任务扩展:
文件:
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代码:
$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
task.json 中的部分代码(选择订阅的输入框):
"inputs": [
{
"name": "ConnectedServiceName",
"type": "connectedService:AzureRM",
"label": "Azure RM Subscription",
"defaultValue": "",
"required": true,
"helpMarkDown": "Select the Azure Resource Manager subscription for the deployment."
},
....
关于powershell - 从 VSTS 版本访问 Azure 服务主体详细信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42852179/