megha
megha

Reputation: 833

How to add task in Azure DevOps release pipeline using rest API

I want to add task in Azure DevOps release pipeline using rest API -

Here is rest API for updating release pipeline -

PUT https://vsrm.dev.azure.com/{organization}/{project}/_apis/release/definitions?api-version=6.0

for example if I want to add powershell task in my existing release pipeline in Dev stage, What request body I need to put ?

enter image description here

Upvotes: 0

Views: 1580

Answers (1)

Edward Han-MSFT
Edward Han-MSFT

Reputation: 3185

After testing(clicking F12 to capture corresponding browser network requests), this request body for this API: Definitions - Update is the same content when you call this API: Definitions - Get to get its definition.

Therefore, you could get the release pipeline definition firstly, and then add below PowerShell task code segment to workflowTasks array, which locates in the result's environments array >>dev stage>>deployPhases array>>workflowTasks array

{
  "environment": {},
  "taskId": "e213ff0f-5d5c-4791-802d-52ea3e7be1f1",
  "version": "2.*",
  "name": "PowerShell Script test",
  "refName": "",
  "enabled": true,
  "alwaysRun": false,
  "continueOnError": false,
  "timeoutInMinutes": 0,
  "definitionType": "task",
  "overrideInputs": {},
  "condition": "succeeded()",
  "inputs": {
    "targetType": "inline",
    "filePath": "",
    "arguments": "",
    "script": "# Write your PowerShell commands here.\n\nWrite-Host \"Hello World\"\n",
    "errorActionPreference": "stop",
    "failOnStderr": "false",
    "showWarnings": "false",
    "ignoreLASTEXITCODE": "false",
    "pwsh": "false",
    "workingDirectory": ""
  }
}

And then there will an extra PowerShell task in Dev stage. enter image description here BTW, each updates will generate a new revision, which is the latest version of release definition, and you need to use the latest version to update release pipeline the next time.

Upvotes: 2

Related Questions