通过REST API跨项目传参调用Pipeline遇500错误求助
我尝试通过REST API,使用System.AccessToken将参数传递给跨项目的Pipeline,具体配置如下:
Project A: deploy.yml
parameters: - name: testparam type: string default: "default" steps: - script: echo hi
Project B: pipeline.yml
jobs: - job: CallDeploymentPipeline pool: Server steps: - task: InvokeRESTAPI@1 displayName: Call different-project Pipeline inputs: connectionType: 'connectedServiceName' serviceConnection: "myGenericServiceConnectionName" method: 'POST' headers: '{ "Authorization":"Bearer $(System.AccessToken)", "Content-Type":"application/json" }' body: '{ "resources": { "repositories": { "self": { "refName": "$(Build.SourceBranch)" } } }, "templateParameters": { "testparam": "test" } }' urlSuffix: '/ProjectA/_apis/pipelines/<deploy pipeline ID>/runs?api-version=7.1' waitForCompletion: 'false'
执行错误信息
Response: An error was encountered while processing request. Exception: {"$id":"1","innerException":null,"message":"The repository RepoA in project could not be retrieved. Verify the name and credentials being used.","typeName":"Microsoft.TeamFoundation.DistributedTask.Pipelines.ResourceValidationException, Microsoft.TeamFoundation.DistributedTask.WebApi","typeKey":"ResourceValidationException","errorCode":0,"eventId":3000}
Exception Message: The remote server returned an error: (500) Internal Server Error. (type WebException)
可正常运行的修改方案
以下任一修改均可让Pipeline正常运行:
- 移除
"templateParameters": { "testparam": "test" }行,不传递参数 - 使用PAT替代
System.AccessToken - 将两个Pipeline迁移至同一项目中
已完成的权限配置
已将组织和项目层级的“限制非发布管道的作业授权范围为当前项目”设置为OFF,且Project Collection Build Service账号已拥有RepoA的读取权限和Project A中部署Pipeline的队列构建权限。
疑问
按照Run Pipeline API文档操作,请问当前操作是否存在错误,还是这是一个已知bug?
内容的提问来源于stack exchange,提问作者Rachel

