我可以在vsts CD任务中使用其他订阅终结点在一个订阅中创建资源组吗?

时间:2019-01-25 05:56:22

标签: azure-devops azure-active-directory azure-powershell

我正在修改CD管道。 我有一个天蓝色的powershell任务,可以使用powershell创建应用程序见解。 参数已通过:

-SubscriptionName $(SubscriptionName) -ResourceGroupName $(ResourceGroupName) -clientID $(clienttestID) -AccessKey $(AccesstestKey)

ResourceGroup(ResourceGroupName)SubscriptionName(SubscriptionName ~~abc)上可用,我正在使用Azure订阅连接xyz。 这是正确的情况,还是会因为我正在创建应用程序见解的资源组处于不同的订阅下而失败?

1 个答案:

答案 0 :(得分:0)

       To create any resources using powershell, you need to be logged in to the same subscription account in which your resource group exist otherwise it will give you an error like below 

enter image description here

       In order to create a application insight under a resource group after switching to a right subscription, you can follow below steps:-



# Connect-AzureRmAccount / Connect-AzureRmAccount
# Set the name of the Application Insights Resource

$appInsightsName = "SampleApp"

# Set the application name used for the value of the Tag "AppInsightsApp" 

$applicationTagName = "My-Sample-App"

# Set the name of the Resource Group to use.  
# Default is the application name.
$resourceGroupName = "My-RG"

###################################################
# Create the Resource and Output the name and iKey
###################################################

Get-AzureRmSubscription -SubscriptionName "Sample Subscription name"

# Select the azure subscription
Select-AzureSubscription -SubscriptionName "Sample Subscription name"

# Create the App Insights Resource

$resource = New-AzureRmResource -ResourceName $appInsightsName -ResourceGroupName $resourceGroupName -Tag @{ applicationType = "web"; applicationName = $applicationTagName} -ResourceType "Microsoft.Insights/components" -Location "East US" -PropertyObject @{"Application_Type"="web"} -Force

# Give owner access to the team

New-AzureRmRoleAssignment `
  -SignInName "myteam@sampleDomain.com" `
  -RoleDefinitionName Owner `
  -Scope $resource.ResourceId 


# Display iKey
Write-Host "App Insights Name = " $resource.Name
Write-Host "IKey = " $resource.Properties.InstrumentationKey

一旦添加了资源,您将可以看到其详细信息,如下所示-

enter image description here