Configurations - Create

创建给定策略类型的策略配置。

POST https://dev.azure.com/{organization}/{project}/_apis/policy/configurations?api-version=7.1-preview.1

URI 参数

名称 必需 类型 说明
organization
path True

string

Azure DevOps 组织的名称。

project
path True

string

项目 ID 或项目名称

api-version
query True

string

要使用的 API 版本。 应将其设置为“7.1-preview.1”才能使用此版本的 API。

请求正文

名称 类型 说明
_links

ReferenceLinks

指向与此对象相关的其他对象的链接。

createdBy

IdentityRef

对创建策略的标识的引用。

createdDate

string

创建策略的日期和时间。

id

integer

策略配置 ID。

isBlocking

boolean

指示策略是否正在阻止。

isDeleted

boolean

指示策略是否已 (软) 删除。

isEnabled

boolean

指示是否启用策略。

isEnterpriseManaged

boolean

如果已设置,此策略需要“管理企业策略”权限才能创建、编辑或删除。

revision

integer

策略配置修订 ID。

settings

JObject

策略配置设置。

type

PolicyTypeRef

策略配置类型。

url

string

可在其中检索策略配置的 URL。

响应

名称 类型 说明
200 OK

PolicyConfiguration

成功的操作

安全性

oauth2

Type: oauth2
Flow: accessCode
Authorization URL: https://app.vssps.visualstudio.com/oauth2/authorize&response_type=Assertion
Token URL: https://app.vssps.visualstudio.com/oauth2/token?client_assertion_type=urn:ietf:params:oauth:client-assertion-type:jwt-bearer&grant_type=urn:ietf:params:oauth:grant-type:jwt-bearer

Scopes

名称 说明
vso.code_write 授予读取、更新和删除源代码、访问有关提交、更改集、分支和其他版本控制项目的元数据的能力。 此外,还授予创建和管理拉取请求和代码评审以及通过服务挂钩接收有关版本控制事件的通知的能力。

示例

Approval count policy
Build policy
Example policy
Git case enforcement policy
Git maximum blob size policy
Merge strategy policy
Work item policy

Approval count policy

Sample Request

POST https://dev.azure.com/fabrikam/fabrikam-fiber-git/_apis/policy/configurations?api-version=7.1-preview.1

{
  "isEnabled": true,
  "isBlocking": false,
  "type": {
    "id": "fa4e907d-c16b-4a4c-9dfa-4906e5d171dd"
  },
  "settings": {
    "minimumApproverCount": 1,
    "creatorVoteCounts": false,
    "scope": [
      {
        "repositoryId": null,
        "refName": "refs/heads/master",
        "matchKind": "exact"
      }
    ]
  }
}

Sample Response

{
  "createdBy": {
    "id": "d6245f20-2af8-44f4-9451-8107cb2767db",
    "displayName": "Normal Paulk",
    "uniqueName": "fabrikamfiber16@hotmail.com",
    "url": "https://vssps.dev.azure.com/fabrikam/_apis/Identities/d6245f20-2af8-44f4-9451-8107cb2767db",
    "imageUrl": "https://dev.azure.com/fabrikam/_api/_common/identityImage?id=d6245f20-2af8-44f4-9451-8107cb2767db"
  },
  "createdDate": "2015-02-23T12:51:06.8887894",
  "isEnabled": true,
  "isBlocking": false,
  "settings": {
    "minimumApproverCount": 1,
    "creatorVoteCounts": false,
    "scope": [
      {
        "refName": "refs/heads/master",
        "matchKind": "Exact",
        "repositoryId": null
      }
    ]
  },
  "_links": {
    "self": {
      "href": "https://dev.azure.com/fabrikam/_apis/policy/configurations/18"
    },
    "type": {
      "href": "https://dev.azure.com/fabrikam/1be3fc5b-c58c-4173-8fd7-6647d11eccd1/_apis/policy/types/fa4e907d-c16b-4a4c-9dfa-4906e5d171dd"
    }
  },
  "revision": 1,
  "id": 18,
  "url": "https://dev.azure.com/fabrikam/_apis/policy/configurations/18",
  "type": {
    "id": "fa4e907d-c16b-4a4c-9dfa-4906e5d171dd",
    "url": "https://dev.azure.com/fabrikam/1be3fc5b-c58c-4173-8fd7-6647d11eccd1/_apis/policy/types/fa4e907d-c16b-4a4c-9dfa-4906e5d171dd",
    "displayName": "Minimum approval count"
  }
}

Build policy

Sample Request

POST https://dev.azure.com/fabrikam/fabrikam-fiber-git/_apis/policy/configurations?api-version=7.1-preview.1

{
  "isEnabled": true,
  "isBlocking": false,
  "type": {
    "id": "0609b952-1397-4640-95ec-e00a01b2c241"
  },
  "settings": {
    "buildDefinitionId": 5,
    "scope": [
      {
        "repositoryId": null,
        "refName": "refs/heads/features/",
        "matchKind": "prefix"
      }
    ]
  }
}

Sample Response

{
  "createdBy": {
    "id": "d6245f20-2af8-44f4-9451-8107cb2767db",
    "displayName": "Normal Paulk",
    "uniqueName": "fabrikamfiber16@hotmail.com",
    "url": "https://vssps.dev.azure.com/fabrikam/_apis/Identities/d6245f20-2af8-44f4-9451-8107cb2767db",
    "imageUrl": "https://dev.azure.com/fabrikam/_api/_common/identityImage?id=d6245f20-2af8-44f4-9451-8107cb2767db"
  },
  "createdDate": "2015-02-23T12:51:06.935666",
  "isEnabled": true,
  "isBlocking": false,
  "settings": {
    "buildDefinitionId": 5,
    "scope": [
      {
        "refName": "refs/heads/features/",
        "matchKind": "Prefix",
        "repositoryId": null
      }
    ]
  },
  "_links": {
    "self": {
      "href": "https://dev.azure.com/fabrikam/_apis/policy/configurations/19"
    },
    "type": {
      "href": "https://dev.azure.com/fabrikam/1be3fc5b-c58c-4173-8fd7-6647d11eccd1/_apis/policy/types/0609b952-1397-4640-95ec-e00a01b2c241"
    }
  },
  "revision": 1,
  "id": 19,
  "url": "https://dev.azure.com/fabrikam/_apis/policy/configurations/19",
  "type": {
    "id": "0609b952-1397-4640-95ec-e00a01b2c241",
    "url": "https://dev.azure.com/fabrikam/1be3fc5b-c58c-4173-8fd7-6647d11eccd1/_apis/policy/types/0609b952-1397-4640-95ec-e00a01b2c241",
    "displayName": "Build"
  }
}

Example policy

Sample Request

POST https://dev.azure.com/fabrikam/fabrikam-fiber-git/_apis/policy/configurations?api-version=7.1-preview.1

{
  "isEnabled": true,
  "isBlocking": true,
  "type": {
    "id": "fd2167ab-b0be-447a-8ec8-39368250530e"
  },
  "settings": {
    "requiredReviewerIds": [
      "1d1dad71-f27c-4370-810d-838ec41efd41"
    ],
    "filenamePatterns": [
      "*/API*.cs"
    ],
    "addedFilesOnly": false,
    "scope": [
      {
        "repositoryId": null,
        "refName": "refs/heads/master",
        "matchKind": "exact"
      },
      {
        "repositoryId": null,
        "refName": "refs/heads/releases/",
        "matchKind": "prefix"
      }
    ]
  }
}

Sample Response

{
  "createdBy": {
    "id": "d6245f20-2af8-44f4-9451-8107cb2767db",
    "displayName": "Normal Paulk",
    "uniqueName": "fabrikamfiber16@hotmail.com",
    "url": "https://vssps.dev.azure.com/fabrikam/_apis/Identities/d6245f20-2af8-44f4-9451-8107cb2767db",
    "imageUrl": "https://dev.azure.com/fabrikam/_api/_common/identityImage?id=d6245f20-2af8-44f4-9451-8107cb2767db"
  },
  "createdDate": "2015-02-23T12:51:06.8106632",
  "isEnabled": true,
  "isBlocking": true,
  "isDeleted": false,
  "settings": {
    "requiredReviewerIds": [
      "1d1dad71-f27c-4370-810d-838ec41efd41"
    ],
    "filenamePatterns": [
      "*/API*.cs"
    ],
    "addedFilesOnly": false,
    "message": null,
    "scope": [
      {
        "refName": "refs/heads/master",
        "matchKind": "Exact",
        "repositoryId": null
      },
      {
        "refName": "refs/heads/releases/",
        "matchKind": "Prefix",
        "repositoryId": null
      }
    ]
  },
  "_links": {
    "self": {
      "href": "https://dev.azure.com/fabrikam/_apis/policy/configurations/17"
    },
    "type": {
      "href": "https://dev.azure.com/fabrikam/1be3fc5b-c58c-4173-8fd7-6647d11eccd1/_apis/policy/types/fd2167ab-b0be-447a-8ec8-39368250530e"
    }
  },
  "revision": 1,
  "id": 17,
  "url": "https://dev.azure.com/fabrikam/_apis/policy/configurations/17",
  "type": {
    "id": "fd2167ab-b0be-447a-8ec8-39368250530e",
    "url": "https://dev.azure.com/fabrikam/1be3fc5b-c58c-4173-8fd7-6647d11eccd1/_apis/policy/types/fd2167ab-b0be-447a-8ec8-39368250530e",
    "displayName": "Required reviewers"
  }
}

Git case enforcement policy

Sample Request

POST https://dev.azure.com/fabrikam/fabrikam-fiber-git/_apis/policy/configurations?api-version=7.1-preview.1

{
  "isEnabled": true,
  "isBlocking": true,
  "type": {
    "id": "7ed39669-655c-494e-b4a0-a08b4da0fcce"
  },
  "settings": {
    "enforceConsistentCase": true,
    "scope": [
      {
        "repositoryId": null
      }
    ]
  }
}

Sample Response

{
  "createdBy": {
    "id": "d6245f20-2af8-44f4-9451-8107cb2767db",
    "displayName": "Normal Paulk",
    "uniqueName": "fabrikamfiber16@hotmail.com",
    "url": "https://vssps.dev.azure.com/fabrikam/_apis/Identities/d6245f20-2af8-44f4-9451-8107cb2767db",
    "imageUrl": "https://dev.azure.com/fabrikam/_api/_common/identityImage?id=d6245f20-2af8-44f4-9451-8107cb2767db"
  },
  "createdDate": "2015-02-23T12:51:06.8106632",
  "isEnabled": true,
  "isBlocking": true,
  "isDeleted": false,
  "settings": {
    "enforceConsistentCase": true,
    "scope": [
      {
        "repositoryId": null
      }
    ]
  },
  "_links": {
    "self": {
      "href": "https://dev.azure.com/fabrikam/_apis/policy/configurations/17"
    },
    "type": {
      "href": "https://dev.azure.com/fabrikam/1be3fc5b-c58c-4173-8fd7-6647d11eccd1/_apis/policy/types/7ed39669-655c-494e-b4a0-a08b4da0fcce"
    }
  },
  "revision": 1,
  "id": 17,
  "url": "https://dev.azure.com/fabrikam/_apis/policy/configurations/17",
  "type": {
    "id": "7ed39669-655c-494e-b4a0-a08b4da0fcce",
    "url": "https://dev.azure.com/fabrikam/1be3fc5b-c58c-4173-8fd7-6647d11eccd1/_apis/policy/types/7ed39669-655c-494e-b4a0-a08b4da0fcce",
    "displayName": "Required reviewers"
  }
}

Git maximum blob size policy

Sample Request

POST https://dev.azure.com/fabrikam/fabrikam-fiber-git/_apis/policy/configurations?api-version=7.1-preview.1

{
  "isEnabled": true,
  "isBlocking": true,
  "type": {
    "id": "2e26e725-8201-4edd-8bf5-978563c34a80"
  },
  "settings": {
    "MaximumGitBlobSizeInBytes": 5242880,
    "useUncompressedSize": false,
    "scope": [
      {
        "repositoryId": null
      }
    ]
  }
}

Sample Response

{
  "createdBy": {
    "id": "d6245f20-2af8-44f4-9451-8107cb2767db",
    "displayName": "Normal Paulk",
    "uniqueName": "fabrikamfiber16@hotmail.com",
    "url": "https://vssps.dev.azure.com/fabrikam/_apis/Identities/d6245f20-2af8-44f4-9451-8107cb2767db",
    "imageUrl": "https://dev.azure.com/fabrikam/_api/_common/identityImage?id=d6245f20-2af8-44f4-9451-8107cb2767db"
  },
  "createdDate": "2015-02-23T12:51:06.8106632",
  "isEnabled": true,
  "isBlocking": true,
  "isDeleted": false,
  "settings": {
    "MaximumGitBlobSizeInBytes": 5242880,
    "useUncompressedSize": false,
    "scope": [
      {
        "repositoryId": null
      }
    ]
  },
  "_links": {
    "self": {
      "href": "https://dev.azure.com/fabrikam/_apis/policy/configurations/17"
    },
    "type": {
      "href": "https://dev.azure.com/fabrikam/1be3fc5b-c58c-4173-8fd7-6647d11eccd1/_apis/policy/types/2e26e725-8201-4edd-8bf5-978563c34a80"
    }
  },
  "revision": 1,
  "id": 17,
  "url": "https://dev.azure.com/fabrikam/_apis/policy/configurations/17",
  "type": {
    "id": "2e26e725-8201-4edd-8bf5-978563c34a80",
    "url": "https://dev.azure.com/fabrikam/1be3fc5b-c58c-4173-8fd7-6647d11eccd1/_apis/policy/types/2e26e725-8201-4edd-8bf5-978563c34a80",
    "displayName": "Required reviewers"
  }
}

Merge strategy policy

Sample Request

POST https://dev.azure.com/fabrikam/fabrikam-fiber-git/_apis/policy/configurations?api-version=7.1-preview.1

{
  "isEnabled": true,
  "isBlocking": true,
  "type": {
    "id": "fa4e907d-c16b-4a4c-9dfa-4916e5d171ab"
  },
  "settings": {
    "useSquashMerge": true,
    "scope": [
      {
        "repositoryId": "1d1dad71-f27c-4370-810d-838ec41efd41",
        "refName": "refs/heads/master",
        "matchKind": "exact"
      }
    ]
  }
}

Sample Response

{
  "createdBy": {
    "id": "d6245f20-2af8-44f4-9451-8107cb2767db",
    "displayName": "Normal Paulk",
    "uniqueName": "fabrikamfiber16@hotmail.com",
    "url": "https://vssps.dev.azure.com/fabrikam/_apis/Identities/d6245f20-2af8-44f4-9451-8107cb2767db",
    "imageUrl": "https://dev.azure.com/fabrikam/_api/_common/identityImage?id=d6245f20-2af8-44f4-9451-8107cb2767db"
  },
  "createdDate": "2015-02-23T12:51:06.935666",
  "isEnabled": true,
  "isBlocking": true,
  "settings": {
    "useSquashMerge": true,
    "scope": [
      {
        "refName": "refs/heads/master",
        "matchKind": "Exact",
        "repositoryId": "1d1dad71-f27c-4370-810d-838ec41efd41"
      }
    ]
  },
  "_links": {
    "self": {
      "href": "https://dev.azure.com/fabrikam/_apis/policy/configurations/19"
    },
    "type": {
      "href": "https://dev.azure.com/fabrikam/1be3fc5b-c58c-4173-8fd7-6647d11eccd1/_apis/policy/types/fa4e907d-c16b-4a4c-9dfa-4916e5d171ab"
    }
  },
  "revision": 1,
  "id": 19,
  "url": "https://dev.azure.com/fabrikam/_apis/policy/configurations/19",
  "type": {
    "id": "fa4e907d-c16b-4a4c-9dfa-4916e5d171ab",
    "url": "https://dev.azure.com/fabrikam/1be3fc5b-c58c-4173-8fd7-6647d11eccd1/_apis/policy/types/fa4e907d-c16b-4a4c-9dfa-4916e5d171ab",
    "displayName": "Require a merge strategy"
  }
}

Work item policy

Sample Request

POST https://dev.azure.com/fabrikam/fabrikam-fiber-git/_apis/policy/configurations?api-version=7.1-preview.1

{
  "isEnabled": true,
  "isBlocking": false,
  "type": {
    "id": "40e92b44-2fe1-4dd6-b3d8-74a9c21d0c6e"
  },
  "settings": {
    "scope": [
      {
        "repositoryId": null,
        "refName": "refs/heads/master",
        "matchKind": "exact"
      }
    ]
  }
}

Sample Response

{
  "createdBy": {
    "id": "d6245f20-2af8-44f4-9451-8107cb2767db",
    "displayName": "Normal Paulk",
    "uniqueName": "fabrikamfiber16@hotmail.com",
    "url": "https://vssps.dev.azure.com/fabrikam/_apis/Identities/d6245f20-2af8-44f4-9451-8107cb2767db",
    "imageUrl": "https://dev.azure.com/fabrikam/_api/_common/identityImage?id=d6245f20-2af8-44f4-9451-8107cb2767db"
  },
  "createdDate": "2015-02-23T12:51:06.935666",
  "isEnabled": true,
  "isBlocking": false,
  "settings": {
    "scope": [
      {
        "refName": "refs/heads/master",
        "matchKind": "Exact",
        "repositoryId": null
      }
    ]
  },
  "_links": {
    "self": {
      "href": "https://dev.azure.com/fabrikam/_apis/policy/configurations/19"
    },
    "type": {
      "href": "https://dev.azure.com/fabrikam/1be3fc5b-c58c-4173-8fd7-6647d11eccd1/_apis/policy/types/40e92b44-2fe1-4dd6-b3d8-74a9c21d0c6e"
    }
  },
  "revision": 1,
  "id": 19,
  "url": "https://dev.azure.com/fabrikam/_apis/policy/configurations/19",
  "type": {
    "id": "40e92b44-2fe1-4dd6-b3d8-74a9c21d0c6e",
    "url": "https://dev.azure.com/fabrikam/1be3fc5b-c58c-4173-8fd7-6647d11eccd1/_apis/policy/types/40e92b44-2fe1-4dd6-b3d8-74a9c21d0c6e",
    "displayName": "Work item linking"
  }
}

定义

名称 说明
IdentityRef
JObject

表示 JSON 对象。

PolicyConfiguration

包含设置的完整策略配置。

PolicyTypeRef

策略类型引用。

ReferenceLinks

表示 REST 引用链接集合的类。

IdentityRef

名称 类型 说明
_links

ReferenceLinks

此字段包含有关图形主题的零个或多个相关链接。 可以调用这些链接来获取有关此图主题的其他关系或更多详细信息。

descriptor

string

描述符是在系统运行时引用图形主题的主要方式。 此字段将唯一标识帐户和组织中的同一图形主题。

directoryAlias

string

已弃用 - 可通过查询 IdentityRef“_links”字典的“self”条目中引用的 Graph 用户来检索

displayName

string

这是图形主题的非唯一显示名称。 若要更改此字段,必须在源提供程序中更改其值。

id

string

imageUrl

string

已弃用 - 在 IdentityRef“_links”字典的“头像”条目中可用

inactive

boolean

已弃用 - 可以通过查询 GraphUser“_links”字典的“membershipState”条目中引用的 Graph 成员身份状态来检索

isAadIdentity

boolean

已弃用 - 可以从描述符的主题类型推断 (描述符.IsAadUserType/Descriptor.IsAadGroupType)

isContainer

boolean

已弃用 - 可以从描述符的主题类型推断 (描述符.IsGroupType)

isDeletedInOrigin

boolean

profileUrl

string

已弃用 - 未在 ToIdentityRef 的大多数预先存在的实现中使用

uniqueName

string

已弃用 - 改用 Domain+PrincipalName

url

string

此 URL 是此图主题的源资源的完整路由。

JObject

表示 JSON 对象。

名称 类型 说明
item

string

type

string

获取此 JToken 的节点类型。

PolicyConfiguration

包含设置的完整策略配置。

名称 类型 说明
_links

ReferenceLinks

指向与此对象相关的其他对象的链接。

createdBy

IdentityRef

对创建策略的标识的引用。

createdDate

string

创建策略的日期和时间。

id

integer

策略配置 ID。

isBlocking

boolean

指示策略是否正在阻止。

isDeleted

boolean

指示策略是否已 (软) 删除。

isEnabled

boolean

指示是否启用策略。

isEnterpriseManaged

boolean

如果已设置,此策略需要“管理企业策略”权限才能创建、编辑或删除。

revision

integer

策略配置修订 ID。

settings

JObject

策略配置设置。

type

PolicyTypeRef

策略配置类型。

url

string

可在其中检索策略配置的 URL。

PolicyTypeRef

策略类型引用。

名称 类型 说明
displayName

string

策略类型的显示名称。

id

string

策略类型 ID。

url

string

可在其中检索策略类型的 URL。

表示 REST 引用链接集合的类。

名称 类型 说明
links

object

链接的只读视图。 由于引用链接是只读的,因此我们只想将其公开为只读。