1

虽然我们可以在 VSTS 中使用 Powershell Azure 任务进行发布,但有时我们也会为发布运行 F# 脚本,作为其中的一部分,我们希望使用服务主体将资产部署到 Azure。我们已经在 VSTS 中注册了 SP,Powershell 可以访问它 - 但是有没有办法让例如原始命令行等访问租户 ID 等,以便我们可以手动使用它们?例如,作为环境变量?

我们唯一的其他选择是手动将租户 ID 等复制到版本中作为构建变量,但这对我来说似乎是一种解决方法。

4

1 回答 1

2

是的,您可以在自定义构建/发布步骤/任务中获取相关信息(例如租户 ID)。

更多关于构建扩展的信息,可以参考:添加构建任务

如果您不知道如何实现,可以参考这些步骤来获取 Azure PowerShell 步骤/任务的所有源代码。

  1. 设置本地构建代理:在 Windows 上部署代理
  2. 创建构建/发布定义
  3. 添加 Azure PowerShell 步骤/任务并进行配置
  4. 将此构建/发布排队
  5. 登录您的构建代理机器,检查 Azure PowerShell 步骤/任务[agent folder]\tasks\AzurePowerShell

简单的构建/发布步骤/任务扩展:

文件:

 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."
    },
....
于 2017-03-17T09:26:01.887 回答