如何使用 Azure Devops rest api 创建 GitHub 服务连接?
您是否正在创建此 GitHub 服务连接?
如果是这样,您应该使用EndPoints-Create API,并且您的 Json Body 可以遵循以下格式:
{
"authorization": {
"scheme": "Token",
"parameters": {"AccessToken": "YourGitHubPAT"}
},
"data": {},
"description": "",
"name": "YourServiceConnectionName",
"serviceEndpointProjectReferences": [{
"description": "",
"name": "YourServiceConnectionName",
"projectReference": {
"id": "YourProjectID",
"name": "YourProjectName"
}
}],
"type": "github",
"url": "https://github.com",
"isShared": false
}
我们应该用您自己的值输入YourGitHubPAT、YourServiceConnectionName(两分中的两次)、YourProjectID 和YourProjectName 的值,以使主体工作。我们可以通过Projects-List API获取YourProjectID。
在 PostMan 中运行后,我可以成功验证它而不会出现问题。我猜您的问题可能与您的参数有关。使用
"authorization": {
"scheme": "Token",
"parameters": {"AccessToken": "<Github_Personal_Access_Token>"}
},
代替
"authorization": {
"scheme": "PersonalAccessToken",
"parameters": {"accessToken": "<Github_Personal_Access_Token>"}
关于如何启用对所有管道的授权访问的更新:
不喜欢 Token、Name 和 Description 等其他元素,Grant Access Permissions to all pipelines 选项由另一个 API 管理。
启用此选项的 API:
https://dev.azure.com/{YourOrganizationName}/{YourProjectName}/_apis/pipelines/pipelinePermissions/endpoint/{YourEndPointID}?api-version=5.1-preview.1
主体:
{
"resource": {
"id": "YourEndPointID",
"type": "endpoint",
"name": ""
},
"pipelines": [],
"allPipelines": {
"authorized": true,
"authorizedBy": null,
"authorizedOn": null
}
}
注意:我们需要在 URL 和 Body 中输入 EnterPointID。 (两次!)
在 PostMan 中,你应该使用 PATCH 方法和 application/json 类型。 YourEndPointID 是ServiceConnectionID,您可以从 EndPoints-Create API 的响应中获取此值。
所以通常要创建启用“授予所有权限...”的服务连接,我们应该先运行 Endpoints-Create,然后运行第二个 API 以启用此选项。
(这也是Web Portal中的行为,当我们在Web浏览器中点击Verify and Save按钮时,它实际上也调用了这两个API来完成这个过程。)