1

I want to update a Pipeline with the Definitions - Update REST API call.

That works fine, but when I want to add a custom task (self made build pipeline task extension) then I struggeling to find the correct task reference id:

Invoke-RestMethod : {"$id":"1","innerException":null,"message":"The pipeline is not valid. A task is missing. The pipeline references a task called '7f1fe94f-b811-4ba1-9d6a-b6c27de758d7'. This 
usually indicates the task isn't installed, and you may be able to install it from the Marketplace: https://marketplace.visualstudio.com. (Task version 1.*, job 'Job_1', step ''.),Job Job_1: Step  
has an invalid task definition reference. A valid task definition reference must specify either an ID or a name and a version specification with a major version 
specified.","typeName":"Microsoft.TeamFoundation.DistributedTask.Pipelines.PipelineValidationException, 
Microsoft.TeamFoundation.DistributedTask.WebApi","typeKey":"PipelineValidationException","errorCode":0,"eventId":3000}

I check out the registrationId of my custom task with the Installed Extensions - List REST API call. But it is not the correct one. (7f1fe94f-b811-4ba1-9d6a-b6c27de758d7)

I also add the custom task manually to a pipeline and read out the correct task refernce id with the Definitions - Get REST API call. I could find the id in:

$pipeline.process.phases.steps.task.id -> 2c7efb3e-3267-4ac6-addc-86e88a6dab34

enter image description here


But how can I read out this id without adding the custom task manually?

This id is obviously dynamic and changes everytime when the custom task get installed, so there must be a way to get this refernce.

Mar Tin
  • 2,132
  • 1
  • 26
  • 46
  • 1
    Is it a task from the Marketplace or it's your own task? – Shayki Abramczyk Oct 30 '19 at 11:08
  • It's a custom task, created by my own. – Mar Tin Oct 30 '19 at 12:36
  • @ShaykiAbramczyk thanks for the hint Shayki. The ID is written inside the `task.json`. Thank you a lot for that. But I there a way to get this ID directly from the Azure DevOps Server? It must have these information, but where? – Mar Tin Oct 30 '19 at 13:01

1 Answers1

3

The task id has not changed every time when the custom task gets installed, but he existed in task.json of the task:

{
    "id": "2f159376-f4dk-4311-a49c-392f9d534113",
    "name": "TaskName",
    "friendlyName": "Task Name",

Another option is to use this api:

https://dev.azure.com/{organiztion}/_apis/distributedtask/tasks

You will get a long list of all the tasks, search your task and you will see the id.

Shayki Abramczyk
  • 36,824
  • 16
  • 89
  • 114
  • It's hard to find if it is not documented, thanks a lot for your answer! – Mar Tin Oct 31 '19 at 05:27
  • 2
    **In addition:** the API call returns potentially a very long `json` response. I had problems to generate an object with PowerShells `Invoke-RestMethod` or `ConvertFrom-Json`. I found to answer to handle very long jsons here: [ConvertFrom-Json max length](https://stackoverflow.com/questions/16854057/convertfrom-json-max-length). **Error Message was:** `Cannot process argument because the value of argument "name" is not valid. Change the value of the "name" argument and run the operation again.` – Mar Tin Oct 31 '19 at 06:04
  • glad i found this. this rest api is so badly / not documented that it is sometimes hard to find what you need. i wanted to add to this that if you already know the id of the task and don't want to run into issues with long lists you can use this api: `https://dev.azure.com/{organiztion}/_apis/distributedtask/tasks/{taskid}` it will return the specific task with al its installed versions. for me it is used in grabbing the extension details (maker + name) from the release definition where i have the taskid available. taskid is not available in the extensions api (for unknown reasons) – Tsteenbakkers Jun 25 '20 at 17:07