【发布时间】:2017-06-07 19:31:09
【问题描述】:
我正在尝试创建一个 VSTS 任务,它应该创建一个 AD 应用程序。 以 DeployAzureResouceGroup 为例,我创建了以下脚本:
[CmdletBinding()]
param()
Trace-VstsEnteringInvocation $MyInvocation
Import-VstsLocStrings "$PSScriptRoot\Task.json"
$connectedServiceNameSelector = Get-VstsInput -Name "connectedServiceNameSelector" -Require
$connectedServiceName = Get-VstsInput -Name "connectedServiceName"
$connectedServiceNameClassic = Get-VstsInput -Name "connectedServiceNameClassic"
$domains = (Get-VstsInput -Name "domains").Split(";")
$appName = Get-VstsInput -Name "appName"
if($connectedServiceNameSelector -eq "ConnectedServiceNameClassic")
{
$connectedServiceName = $connectedServiceNameClassic
$action = $actionClassic
$resourceGroupName = $cloudService
}
Import-Module $PSScriptRoot\ps_modules\VstsAzureHelpers_
Initialize-Azure
# Import the loc strings.
Import-VstsLocStrings -LiteralPath $PSScriptRoot/Task.json
# Import all the dlls and modules which have cmdlets we need
Import-Module "$PSScriptRoot\DeploymentUtilities\Microsoft.TeamFoundation.DistributedTask.Task.Deployment.Internal.psm1"
Import-Module "$PSScriptRoot\DeploymentUtilities\Microsoft.TeamFoundation.DistributedTask.Task.Deployment.dll"
# Load all dependent files for execution
. "$PSScriptRoot\Utility.ps1"
try
{
Validate-AzurePowerShellVersion
$azureUtility = Get-AzureUtility "$connectedServiceName"
Write-Verbose "Loading $azureUtility"
. "$PSScriptRoot\$azureUtility"
Write-Output "test"
Write-Output "Creating a new Application in AAD (App URI -)" -Verbose
$azureAdApplication = New-AzureRmADApplication -DisplayName "test" -IdentifierUris "https://app.com" -HomePage "https://app.com"
$appId = $azureAdApplication.ApplicationId
Write-Output "Azure AAD Application creation completed successfully (Application Id: $appId)" -Verbose
Write-Verbose "Completing Azure Resource Group Deployment Task" -Verbose
}
catch
{
Write-TaskSpecificTelemetry "UNKNOWNDEP_Error"
throw
}
当我将服务主体用作服务端点用户时,我收到错误资源我未找到。
当我使用自定义 AD 帐户时,出现错误:Run Login-AzureRmAccount to login。
我做错了什么?我怎样才能让这个脚本工作?
【问题讨论】:
-
基于这些链接(answers.flyppdevportal.com/MVC/Post/Thread/… 和stackoverflow.com/questions/34762918/…),不可能从一个服务主体创建另一个服务主体,所以不可能用你的方式来实现。您可以在 Azure PowerShell 步骤中调用 New-AzureRmADApplication 命令来验证它(抛出相同的错误)。
-
您可以尝试使用用户名和密码 (returngis.net/en/2015/06/…) 进行身份验证,然后调用该命令。
-
使用Azure AD账号时,将“New-AzureRmADApplication”改为“New-AzureADApplication”再试一次。
标签: azure-powershell azure-pipelines-build-task