I am using the REST APIs of Azure DevOps to work with a release pipeline.
The release pipeline uses task as part of an agent job.
This task deploys a VM into Azure using an ARM Template file and a parameters file.
So far I can execute the release pipeline successfully with the Azure DevOps REST APIs and it deploys the VM successfully with the code below.
Using the GUI I can also successfully customize the release pipeline when executed. For example I can add values to the “override template parameters” field below in the screenshot.
However after searching I see nothing from Microsoft on how to access fields within tasks when executing a release pipeline in their Azure DevOps REST API documentation.
How can I modify my “response body” in the code below to access one of the fields in a pipeline task such as “override template parameters” when I call this pipeline?
const sendHttpRequest = (method, url, reqBody) =>
{
const promise = new Promise((resolve,reject) =>
{
const request = new XMLHttpRequest();
request.open(method, url, true); // Send a request
request.setRequestHeader('Content-Type', 'application/json'); // Build the request header
request.setRequestHeader ("Authorization", "Basic " + btoa('Basic' + ":" + pat)); // Supply authentication
request.onload = () =>
{ // Retrieve the response
// Check the status of the request...
if (request.status >= 200 && request.status < 400)
{
myOutput.innerHTML = "Request Status: Valid | ";
resolve(request.response);
}
else
{
myOutput.innerHTML = "Request Status: Invalid |";
reject(request.response);
}
} // onload
request.send(JSON.stringify(reqBody));
}); // promise
return promise;
};
/*
Execute a pipeline
*/
function run_pipeline()
{
var reqLink = 'https://dev.azure.com/'+ org_name+'/'+ prj_name+'/_apis/pipelines/'+pipeline_id+'/runs?api-version=6.0-preview.1';
// CHANGE RESPONSE BODY TO THE DESIRED PIPELINE NEEDED TO BE RUN
responseBody = {
"previewRun": "false",
"resources": null,
"stagesToSkip": null,
"templateParameters": null,
"variables": null,
"yamlOverride": null
};
sendHttpRequest('POST', reqLink, responseBody).then(responseData =>
{
// parse the obtained data
var data = JSON.parse(responseData);
myOutput.innerHTML += " Pipeline Executed!";
console.log(data);
})
.catch(error =>
{
var message = JSON.parse(error);
myOutput.innerHTML += " Error with Data...";
console.log(message);
});
};