mark
mark

Reputation: 62712

Is it possible to author a custom Azure DevOps task in Powershell?

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?

Upvotes: 0

Views: 242

Answers (2)

Shayki Abramczyk
Shayki Abramczyk

Reputation: 41545

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.

Upvotes: 1

Cece Dong - MSFT
Cece Dong - MSFT

Reputation: 31003

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)"
    }
 }

Upvotes: 1

Related Questions