Search code examples
azure-devopsazure-pipelinesazure-devops-rest-api

Pass parameter to a different-project pipeline via REST api using System.AccessToken


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'

I get back:

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)

This works if any one of the following are changed:

  1. No parameter is passed (i.e. this line is removed "templateParameters": { "testparam": "test" })
  2. OR PAT is used vs System.AccessToken
  3. OR Pipelines are placed in the same project

Yes, I have followed the docs and set Limit job authorization scope to current project for non-release pipelines OFF for the org and project.

Yes, Project Collection Build Service has Read access to my repo and Queue Build permission to deploy pipeline.

Run Pipeline api docs

Am I doing anything wrong or is this a bug?


Solution

  • I can reproduce the same error:

    enter image description here

    This is due to the lack of permission on Project A pipeline, please Manage security on Project A pipeline -> set Edit queue build configuration as Allow for Project Collection Build Service(orgname).

    Permission on my side for your reference:

    enter image description here

    The result:

    enter image description here