Create custom VSTS build task - Part 1
When I was first introduces to CI/CD almost two years ago, Bitrise was my go-to platform for all of my continuous integration needs. From their easy-to-use interface to their integration with GitHub and iTunes Connect to deploy my apps to the app-store all by just committing and pushing my code, it fast became my default CI platform. But what really stood out was the Slack integration for my workflows. Now since moving all my projects over to Visual Studio Team Services and Microsoft App Center, Slack integration was not an out of the box offering. So I decided to integrate it myself by creating a custom VSTS build task.
First, we need to download the VS Team Services CLI. This will help up scaffold out our project as well as the ability upload the build task right from the command prompt. Run this command to install the CLI:
$ npm install –g tfx-cli
We then want to login. You can login using basic auth or a personal access token (PAT). I will be using a PAT to login. To generate the token, I went to the security tab on my VSTS account.
- Run the command tfx-login
- Provide your service URL, this is your VSTS account url i.e. https://youraccountname.visualstudio.com/DefaultCollection NB: Do not forget “DefaultCellection”
- Next, paste in your personal access token to complete the process.
Once we’re logged in, we can create new build tasks with a familiar the ‘File > New’ experience we get in Visual Studio.
- Run the command tfx build tasks create
- Answer the questions that follow, and you will have created an empty build task.
An empty task project is made up of the following files:
- A 32x32px icon.png image which serves as the default icon for your task.
- A sample.pst with the PowerShell build task logic
- A task.json with the metadata of your build task. This is also where you specify the required inputs for your task to run.
You then want to create a tsconfig file and change it to ES6 for asyc-wait support.
This was a brief introduction to creating a custom task for VSTS (Visual Studio Team Services) that you may want to run during your build process in your CI pipeline.
Now that we have the scaffolding out the way, let’s implement our task, by adding Slack to send messages to our channel.