Home > Software engineering >  Create task in TFS via PowerShell
Create task in TFS via PowerShell

Time:02-25

I need to create a task in TFS with PowerShell

I used the VSTeam (A PowerShell module for many features in TFS / Azure DevOps). The item is created. I have a template for the description but i don't know how to insert it to -Description that gets a string Here is an example of the template: The build is an hyper link and also the tfs item (patch XXXX) How can I built the string like this? How to create a link for items? How to set a bold string? Can I copy a link from TFS?

There is a new build. The build location:

\\XXXXX\global\QA\

The patches that were added:

Patch 1269263: "Title"
Patch 1271540: "Title"

CodePudding user response:

Have you looked into VSTeam? A PowerShell module for many features in TFS / Azure DevOps.

Set-VSTeamAccount -Account http://localtfs:8080/tfs/DefaultCollection -UseWindowsAuthentication
Set-VSTeamDefaultProject Demo
Add-VSTeamWorkItem -Title "New Work Item" -WorkItemType Task

ID Title          Status
-- -----          ------
6  New Work Item  To Do

The description field in TFS/Azure DevOps contains HTML text. Any formatting can be done using standard HTML constructs. <i> for italic, <b> for bold <a href="https://....."> for links.

To get the links you may need to invoke other REST APIs to get the build details. Most APE results have a links collection with a web link you can use to direct people to the web page for that thing.

Example from a Build/GET API call:

GET https://dev.azure.com/jessehouwing/a88536a2-a889-45a3-a955-ddf1af8aeba1/_apis/build/builds/2817

{
    "_links": {
        "self": {
            "href": "https://dev.azure.com/jessehouwing/a88536a2-a889-45a3-a955-ddf1af8aeba1/_apis/build/Builds/2817"
        },
        "web": {
            "href": "https://dev.azure.com/jessehouwing/a88536a2-a889-45a3-a955-ddf1af8aeba1/_build/results?buildId=2817"
        },
        "sourceVersionDisplayUri": {
            "href": "https://dev.azure.com/jessehouwing/a88536a2-a889-45a3-a955-ddf1af8aeba1/_apis/build/builds/2817/sources"
        },
        "timeline": {
            "href": "https://dev.azure.com/jessehouwing/a88536a2-a889-45a3-a955-ddf1af8aeba1/_apis/build/builds/2817/Timeline"
        },
        "badge": {
            "href": "https://dev.azure.com/jessehouwing/a88536a2-a889-45a3-a955-ddf1af8aeba1/_apis/build/status/36"
        }
    },
    ...
    ...
}

In this case self is the link that retrieved this document. web is the equivalent in the WebUI, etc.

You'll find that other elements returned by the API carry a url property. By folliwing that URL, you'll get the _links collection for that object as well:

    ...
    ...
    "project": {
        "id": "a88536a2-a889-45a3-a955-ddf1af8aeba1",
        "name": "azure-devops-extensions",
        "description": "This projects hosts the pipelines for all my Azure DevOps marketplace extensions.",
        "url": "https://dev.azure.com/jessehouwing/_apis/projects/a88536a2-a889-45a3-a955-ddf1af8aeba1",
        "state": "wellFormed",
        "revision": 414360082,
        "visibility": "public",
        "lastUpdateTime": "2019-06-28T09:48:16.943Z"
    },

Following:

GET https://dev.azure.com/jessehouwing/_apis/projects/a88536a2-a889-45a3-a955-ddf1af8aeba1

{
    "id": "a88536a2-a889-45a3-a955-ddf1af8aeba1",
    "name": "azure-devops-extensions",
    "description": "This projects hosts the pipelines for all my Azure DevOps marketplace extensions.",
    "url": "https://dev.azure.com/jessehouwing/_apis/projects/a88536a2-a889-45a3-a955-ddf1af8aeba1",
    "state": "wellFormed",
    "revision": 414360082,
    "_links": {
        "self": {
            "href": "https://dev.azure.com/jessehouwing/_apis/projects/a88536a2-a889-45a3-a955-ddf1af8aeba1"
        },
        "collection": {
            "href": "https://dev.azure.com/jessehouwing/_apis/projectCollections/6ac92044-9ce2-40d0-b882-f6b6648dff8b"
        },
        "web": {
            "href": "https://dev.azure.com/jessehouwing/azure-devops-extensions"
        }
    },
    "visibility": "public",
    "defaultTeam": {
        "id": "7edc4d0a-3d22-44ee-a6cd-96a3dbf0690f",
        "name": "azure-devops-extensions Team",
        "url": "https://dev.azure.com/jessehouwing/_apis/projects/a88536a2-a889-45a3-a955-ddf1af8aeba1/teams/7edc4d0a-3d22-44ee-a6cd-96a3dbf0690f"
    },
    "lastUpdateTime": "2019-06-28T09:48:16.943Z"
}

This way you can collect the links to the appropriate UI pages to direct your users to.

  • Related