1

I have an Azure Pipelines Task which uses the azure-pipelines-task-lib (https://github.com/microsoft/azure-pipelines-task-lib) and need to get the version of the task from within my task code (TypeScript). I figured there would be an easy way to do this using the azure-pipelines-task-lib library but if there is, I haven't found it.

The version is specified in the task.json file which is packaged up into the artifact that is built when you're publishing a task and I could parse that easily enough, it just seems a bit kludgy to do so. Does anyone know of a better way of doing this?

Thanks!

maxjeffos
  • 63
  • 3

1 Answers1

0

There is no easy way to get task version using the azure-pipelines-task-lib, parse the task.json file is the usual way we can do currently.

Cece Dong - MSFT
  • 29,631
  • 1
  • 24
  • 39
  • How do I find the task.json in a deployed task? I can easily parse the task.json in my dev environment, but once I run it in an Azure Pipeline, the task.json does not appear to be anywhere where I can read it. Is there some path I can look in to find this file in a deployed Pipeline? Thanks – maxjeffos Apr 19 '20 at 13:50
  • You can try to get directory of the current folder that the task execute and read the `task.json` file. – Cece Dong - MSFT Apr 20 '20 at 06:40
  • @maxjeffos Are you able to get `task.json` file? – Cece Dong - MSFT Apr 23 '20 at 08:50
  • 1
    Hi @Cece Dong - MSFT, yes I was able to get the task.json file using this: ``` const taskJsonPath = path.join(__dirname, "..", "task.json"); ``` With that I just parsed out the version from the task file by first using `JSON.parse(...)` and then grabbing the Major/Minor/Patch fields. Thanks! – maxjeffos Apr 30 '20 at 23:19