azure-devops-extension-task-boilerplate project: Help you to author azure pipeline agent task
Azure pipeline helps you to implement continuous integration and continuous delivery(CI/CD) for your application. When you create a pipeline, Task is the fundamental building block in the pipeline. A task is just a packaged script or procedure helps you to make the job done, for example, VSTest task, VSBuild task.
Microsoft provides out-of-the-box tasks with Azure pipelines on azure-pipelines-tasks repo.
When we talk about writing tasks, actually there are two kinds of tasks:
- agent task. Eg, Install Windows Application Driver on the agent
- server task. Eg, query work items from GitHub, monitoring Azure
Hereafter I just talk about agent task. Below is the reason that I need to implement a custom task:
WinAppDriver v1.1 is included in ‘windows 2019’ Microsoft hosted agent, and it takes time to make the hosted agent to be prebuilt with latest WinAppDriver, so I need a tool to help me to change WinAppDriver to a different version on the agent before I start my testing. In the pipeline, I expected to use the task like this
So I started from the this tutorial. Generally speaking, I can use PowerShell or node to write this task, since the example is node, and I use node too. After I completed my task, I found azure-devops-extension-tasks, and it has better organization than the tutorial, and it provides:
- package one or more tasks in the same extension
- easy command to init, build, and package the extension.
So based on azure-devops-extension-tasks repo, I created azure-devops-extension-task-boilerplate. After you clone this repo, just run
npm run package.Then your first task is ready to ship.
In the boilerplate, BuildTasks folder is added, which is used to supports multiple tasks in the same extension
In the root directory, it includes:
overview.md/license.txt/icon.png — Describe the package, license, and icon showed in azure marketplace
package.json — A lot of scripts help you to manage, build and package tasks. Here are some important commands:
- From the root of the repo run
npm run initdev. This will pull down the necessary modules and TypeScript declare files.
npm run buildto compile all tasks.
npm run packageto create a .vsix extension package that includes the build tasks.
Based on the boilerplate, I implemented WinAppDriverInstaller. To uninstall and install WinAppDriver, it requires privilege permission. Finally I found node-windows project, which Elevate and makes the command to execute with elevated privileges.