Azure devops Azure DevOps REST API已损坏导入私有Git存储库
正在尝试使用REST API将私有GitHub存储库导入Azure DevOps: 毫不奇怪,文档不起作用 我在DevOps项目中有一个基于PAT的服务端点,可以访问我试图导入的GitHub存储库 下面的PowerShell代码片段再现了这个问题Azure devops Azure DevOps REST API已损坏导入私有Git存储库,azure-devops,azure-devops-rest-api,Azure Devops,Azure Devops Rest Api,正在尝试使用REST API将私有GitHub存储库导入Azure DevOps: 毫不奇怪,文档不起作用 我在DevOps项目中有一个基于PAT的服务端点,可以访问我试图导入的GitHub存储库 下面的PowerShell代码片段再现了这个问题 $headers=@{ 授权=“持票人****” } $org='***' $project='***' $targetRepositoryId='***' $sourceRepositoryUrl='***' $gitHubServiceEndpo
$headers=@{
授权=“持票人****”
}
$org='***'
$project='***'
$targetRepositoryId='***'
$sourceRepositoryUrl='***'
$gitHubServiceEndpointId='***'
irmhttps://dev.azure.com/$org/$project/_api/git/repositories/$targetRepositoryId/importRequests?api版本=6.0-preview.1-方法Post-标题$Headers-内容类型应用程序/json-正文@”
{
“参数”:{
“gitSource”:{
“覆盖”:false,
“url”:“$sourceRepositoryUrl”
},
“serviceEndpointId”:“$gitHubServiceEndpointId”,
“deleteServiceEndpointAfterImportIsDone”:false
}
}
"@
在没有其他信息的情况下引发400错误(错误请求)
如果我将GitHub存储库公开,那么上面完全相同的API请求和代码就可以了
我还100%确定服务端点可以访问相关存储库,因为我在Azure DevOps中有管道使用此服务端点从GitHub克隆所述存储库。根据捕获的网络日志,创建服务连接时,服务连接类型需要为“其他Git”,然后输入在GitHub中创建的Git存储库URL和个人访问令牌: 使用此服务连接ID,应该能够成功导入
只有使用UsernamePassword授权方案创建服务连接时,我才能使用GitHub服务连接使导入工作正常——这是从DevOps本身无法做到的,必须从API做到:
irm "https://dev.azure.com/org/project/_apis/serviceendpoint/endpoints?api-version=6.0-preview.1" -Method Post -Headers $headers -ContentType application/json -Body @"
{
"authorization": {
"scheme": "UsernamePassword",
"parameters": {
"username": "foo",
"password": "github access token"
}
},
"name": "Test-5",
"serviceEndpointProjectReferences": [
{
"description": "",
"name": "Test-5",
"projectReference": {
"id": "project id",
"name": "projectName"
}
}
],
"type": "github",
"url": "https://github.com",
"isShared": false,
"owner": "library"
}
"@
对于具有管道YML的存储库,我是否可以使用该端点而不是GitHub服务端点?我唯一能够使其工作的方法是在设置服务连接时添加用户名和令牌。@Jeff Pipelines仅支持存储库类型的以下值:
git
,GitHub
,githubenterprise
和bitbucket
。git
类型指的是Azure回购git回购。查看此处了解更多详细信息:。很好的发现!听起来MS不知道这是怎么回事。