共用方式為


Configurations - Create

建立指定原則類型的原則組態。

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

URI 參數

名稱 位於 必要 類型 Description
organization
path True

string

Azure DevOps 組織的名稱。

project
path True

string

專案識別碼或專案名稱

api-version
query True

string

要使用的 API 版本。 這應該設定為 '7.1-preview.1' 以使用此版本的 API。

要求本文

名稱 類型 Description
_links

ReferenceLinks

與這個物件相關的其他物件連結。

createdBy

IdentityRef

建立原則之身分識別的參考。

createdDate

string

建立原則的日期和時間。

id

integer

原則組態識別碼。

isBlocking

boolean

指出原則是否封鎖。

isDeleted

boolean

指出原則是否已 (虛) 刪除。

isEnabled

boolean

指出是否啟用原則。

isEnterpriseManaged

boolean

如果設定,此原則需要「管理企業原則」許可權,才能建立、編輯或刪除。

revision

integer

原則設定修訂識別碼。

settings

JObject

原則組態設定。

type

PolicyTypeRef

原則組態類型。

url

string

可以擷取原則設定的 URL。

回應

名稱 類型 Description
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

名稱 Description
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"
  }
}

定義

名稱 Description
IdentityRef
JObject

表示 JSON 物件。

PolicyConfiguration

具有設定的完整原則組態。

PolicyTypeRef

原則類型參考。

ReferenceLinks

表示 REST 參考連結集合的類別。

IdentityRef

名稱 類型 Description
_links

ReferenceLinks

此欄位包含圖表主旨的相關零或更多有趣連結。 您可以叫用這些連結來取得其他關聯性,或取得此圖表主體的詳細資訊。

descriptor

string

描述項是在系統執行時參考圖形主旨的主要方式。 此欄位可唯一識別帳戶和組織之間的相同圖表主旨。

directoryAlias

string

已被取代 - 您可以藉由查詢 IdentityRef 「_links」 字典的 「self」 專案中參考的 Graph 使用者來擷取

displayName

string

這是圖形主體的非唯一顯示名稱。 若要變更此欄位,您必須變更來源提供者中的值。

id

string

imageUrl

string

已淘汰 - 可在 IdentityRef 「_links」 字典的 「avatar」 專案中使用

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 物件。

名稱 類型 Description
item

string

type

string

取得這個 JToken 的節點類型。

PolicyConfiguration

具有設定的完整原則組態。

名稱 類型 Description
_links

ReferenceLinks

與這個物件相關的其他物件連結。

createdBy

IdentityRef

建立原則之身分識別的參考。

createdDate

string

建立原則的日期和時間。

id

integer

原則組態識別碼。

isBlocking

boolean

指出原則是否封鎖。

isDeleted

boolean

指出原則是否已 (虛) 刪除。

isEnabled

boolean

指出是否啟用原則。

isEnterpriseManaged

boolean

如果設定,此原則需要「管理企業原則」許可權,才能建立、編輯或刪除。

revision

integer

原則設定修訂識別碼。

settings

JObject

原則組態設定。

type

PolicyTypeRef

原則組態類型。

url

string

可以擷取原則設定的 URL。

PolicyTypeRef

原則類型參考。

名稱 類型 Description
displayName

string

原則類型的顯示名稱。

id

string

原則類型識別碼。

url

string

可以擷取原則類型的 URL。

表示 REST 參考連結集合的類別。

名稱 類型 Description
links

object

連結的唯讀檢視。 因為參考連結是唯讀的,所以我們只想要將它們公開為唯讀。