0

We use Azure DevOps Server 2019 (on-prem).

I would like to author a custom Azure DevOps task in Powershell. The examples I have seen so far on the web are about authoring it in Typescript.

I wonder - is it the only way? Can we use Powershell, for instance?

Shayki Abramczyk
  • 36,824
  • 16
  • 89
  • 114
mark
  • 59,016
  • 79
  • 296
  • 580

2 Answers2

1

Yes, you can use the PS script directly in your custom task. You can configure task.json in this way:

"execution": {
    "PowerShell3": {
        "target": "script.ps1",
         "workingDirectory": "$(currentDirectory)"
    }
 }
Cece Dong - MSFT
  • 29,631
  • 1
  • 24
  • 39
1

Yes, you can use PowerShell in your custom build task.

You need to edit this section in task.json:

  "execution": {
    "PowerShell3": {
      "target": "ps-script.ps1",
      "workingDirectory": "$(currentDirectory)"
    }
  }

And you need to install the VstsTaskSdk Powershell Module:

  • open up Powershell
  • navigate to the root/buildtask of directory of your extension
  • execute mkdir ps_modules and then navigate into the new directory
  • your pwd should read root/buildtask/ps_modules
  • execute Save-Module -Name VstsTaskSdk -Path . which will save the module to disk.
  • Flatten the directory structure by removing the version number. For example you will have a path of root/buildtask/ps_modules/VstsTaskSdk/0.10.0/* which should now read root/buildtask/ps_modules/VstsTaskSdk/*

A full tutorial exist here.

You can also see an example for custom task with PS on this GitHub repo.

Note: it works only in windows machines.

Shayki Abramczyk
  • 36,824
  • 16
  • 89
  • 114