【问题标题】:'Unexpected character' error while executing New-AzPolicyDefinition in Azure Powershell在 Azure Powershell 中执行 New-AzPolicyDefinition 时出现“意外字符”错误
【发布时间】:2020-01-30 06:56:18
【问题描述】:

在尝试使用 Azure powershell 创建新策略定义时抛出以下异常,如果 cmdlet 或定义文件中存在错误,请告诉我。

New-AzPolicyDefinition:解析值时遇到意外字符:

我使用了以下命令,策略定义和参数定义是从 azure devops (git) 存储库中引用的,

$definition = New-AzPolicyDefinition -Name "application-role-tag" -DisplayName "Allow resource creation if Application Role tag value in allowed values" -description "Allows resource creation if the Application Role tag is set to one of the following values: webServer, appServer, data." -Policy 'https://company.visualstudio.com/DefaultCollection/Gullfoss/_git/Azure Governance?path=/Policies/Tags/application-role-tag/azurepolicy.rules.json' -Parameter 'https://company.visualstudio.com/DefaultCollection/Gullfoss/_git/Azure Governance?path=/Policies/Tags/application-role-tag/azurepolicy.parameters.json' -Mode Indexed

策略定义文件:

{
    "properties": {
      "displayName": "Allow resource creation if 'application role' tag value in allowed values",
       "policyType": "Custom",
       "mode": "Indexed",
       "description": "Allows resource creation if the 'application role' tag is set to one of the following values: webserver, appserver, data, gateway, messageBroker.",
       "parameters": {},
       "policyRule": {
          "if": {
             "not": {
                "field": "tags['applicationRole']",
                "in": [
                   "webServer",
                   "appServer"                  
                ]
             }
          },
          "then": {
             "effect": "audit"
          }
       }
    }
 }

策略参数定义:

{
    "parameters": {}
}

【问题讨论】:

    标签: azure-powershell azure-policy


    【解决方案1】:

    我错误地引用了网页 url,而不是使用 DevOps REST API 获取文件内容。获取文件内容的url如下:

    https://dev.azure.com/{organization}/{project}/_apis/sourceProviders/{providerName}/filecontents?repository={repository}&commitOrBranch={commitOrBranch}&path={path}&api-version=5.1-preview.1
    

    {providerName}:tfsgit 或 tfvs {commitOrBranch}:分支名称,如'master'

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-02-06
      • 1970-01-01
      • 1970-01-01
      • 2014-09-29
      • 1970-01-01
      相关资源
      最近更新 更多