Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/security/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Powershell 从VSTS版本访问Azure服务Prinicpal详细信息_Powershell_Security_Azure_Azure Pipelines Release Pipeline_Azure Devops Rest Api - Fatal编程技术网

Powershell 从VSTS版本访问Azure服务Prinicpal详细信息

Powershell 从VSTS版本访问Azure服务Prinicpal详细信息,powershell,security,azure,azure-pipelines-release-pipeline,azure-devops-rest-api,Powershell,Security,Azure,Azure Pipelines Release Pipeline,Azure Devops Rest Api,虽然我们能够在VSTS中使用Powershell Azure任务进行发布,但有时我们也会为发布运行F脚本,作为这一过程的一部分,我们希望使用服务主体将资产部署到Azure。我们已经在VSTS中注册了SP,Powershell可以访问它-但是是否有办法(例如原始命令行等)访问租户Id等,以便我们可以手动使用它们?例如,作为环境变量 我们唯一的另一种选择是将租户id等作为构建变量手动复制到版本中,但这对我来说似乎是一种解决方法。是的,您可以在自定义构建/发布步骤/任务中获取相关信息,例如租户id 有

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


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

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

有关生成扩展的详细信息,请参阅:

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

设置内部构建代理: 创建生成/发布定义 添加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?我想知道我们是否可以通过.NET代码访问它?@IsaacAbraham它使用vsts任务库获取端点,这是powershell代码,但您可以从.NET代码调用powershell脚本。