1

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.

snippet of the GUI

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);
    });
};
3
  • Hi Did you get a chance to check out below rest api. how did it go? – Levi Lu-MSFT Commented Jun 17, 2020 at 9:13
  • Hi, yes it worked. However, I am looking for a way to update the storageName parameter from fabrikam to "foo". Commented Jun 17, 2020 at 20:54
  • Hi @Malik you can use create release rest api to update the storageName parameter. Please check out below update. Commented Jun 18, 2020 at 9:17

1 Answer 1

2

If you need to get the the fields in a release pipeline task. You might need to use get release rest api

GET https://vsrm.dev.azure.com/{organization}/{project}/_apis/Release/releases/{releaseId}/environments/{environmentId}?api-version=6.0-preview.6

You can get the release id and environment id from the Release ui address bar. see below:

enter image description here

Then you will find the fields of the task in response (deployPhasesSnapshot -->workflowTasks-->inputs)

enter image description here

Update:

If you want to update the storageName parameter. Please follow below steps:

1, create a pipline variable named storageName. And check Settable at release time. See below screenshot:

enter image description here

2, Set the override template parameters field of the deployment task as below:

enter image description here

3, If you want to create a new release. You can call create release rest api

POST https://vsrm.dev.azure.com/{organization}/{project}/_apis/release/releases?api-version=5.1

Then update the pipeline variable storageName in the request body. See below:

Request Body:

{
    "definitionId": 7,

    "variables": {  
                    "storageName": {
                                      "value": "foo" 
                                   }
                 }
}

Then the storageName parameter will be overrode to "foo".

Update 2:

If you want to update a existing release. You need to call update release environment rest api

 PATCH https://vsrm.dev.azure.com/{organization}/{project}/_apis/Release/releases/{releaseId}/environments/{environmentId}?api-version=5.1-preview.6.

First you need to set the pipeline variable storageName scope to its stage. See below:

enter image description here

Then update the storageName value in the request body. And set status to inProgress to redeploy the stage. So that the overrode storageName will be reflected in the release.

{
    "status": "inProgress",


    "variables": {  
                    "storageName": {
                                      "value": "storageName-rest-api-three" 
                                   }
                 }
}
Sign up to request clarification or add additional context in comments.

3 Comments

I apologize for being unclear, I do want to update an existing release pipeline's variable. Would the request body you have above work?
Hi @Malik. Please check out above update 2. I tested above request body and it was working.
Hi @Levi how would I create a new release with a pipeline variable at a specific stage?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.