Create custom VSTS build task - Part 2
There are many ways to integrate Ingrate Slack into your products, for this particular task I decided to use webhooks to send my messages. Head on over to Slack’s API documentation to set up a webhook.
First, we need to add the Slack Node SDK.
$ npm install @slack/client
Our task will accept a number of inputs.
- A Webhoook URL to send the messages to
- The channel we would like to send our messages to (optional)
- The name you would like to send the messages as (optional)
- The message we want to send.
To pass in these values during the setup of our task, we have to create inputs for our task. Copy the following into yout tasks.json file
Once know our input fields, we can go ahead and implement the logic for our Slack messenger.
Next, we want to upload our task to Visual Studio Team Services so that we can use it for our builds. Upload the task by running the following command:
$ tfx build tasks upload -task.path ./pathToYourTask
Once the upload has completed successfully, Head on over to VSTS and edit one of your build definitions to add your custom task to the build pipeline.
Creating custom build task is a great way to customize your build definitions and have it do everything you need it to do, except this time it’s all automated and you can carry on with the things that matter, Crushing Code All Day.
This task and all it’s code is up on GitHub here should you be having any trouble setting up the project.