modify your Azure DevOps YAML pipeline to accept a parameter
parameters:
- name: agentName
displayName: Agent Name
type: string
default: 'DefaultPool'
pool:
${{ if eq(parameters.agentName, 'DefaultPool') }}:
name: DefaultPool
${{ if ne(parameters.agentName, 'DefaultPool') }}:
name: ${{ parameters.agentName }}
The REST API endpoint to trigger a pipeline is
POST https://dev.azure.com/{organization}/{project}/_apis/pipelines/{pipelineId}/runs?api-version=7.1-preview.1
The request body should include the parameter
{
"templateParameters": {
"agentName": "CustomAgentPool"
}
}
API call to trigger the pipeline
const AZURE_PIPELINE_URL = 'https://dev.azure.com/{organization}/{project}/_apis/pipelines/{pipelineId}/runs?api-version=7.1-preview.1';
fetch(AZURE_PIPELINE_URL, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': 'Basic ' + AZURE_PERSONAL_ACCESS_TOKEN,
},
body: JSON.stringify({
templateParameters: {
agentName: 'CustomAgentPool'
}
}),
})