For some of my demos, I had to create custom tasks which I shared on GitHub. In this post, I will show you how you can use those in your demos by uploading the task to your Visual Studio Team Services (VSTS) account.
The tool we are going to be using is tfx-cli. Before we can install this tool we have to get npm. There are two ways to get npm: node or io.js. For this post, we are going to go the node route.
To begin I download and install node for Windows. However, the tool is multi-platform and can be run on Linux or Mac. I installed node accepting all the defaults. The default setting should add npm to your path. Open a command window and type the following to verify:
Now with npm installed, we can install tfx-cli. To install, type:
npm install -g tfx-cli
Once the install is complete, you can type the following at the command prompt to verify the installation was successful:
To connect to your VSTS account you are going to need a Personal Access Token.
- Log into VSTS
- Click your name in the upper right-hand corner
- Click My security
- Click Add under Personal access tokens
- Give the access token a name
- Select how long you want the token to be valid
- Select the accounts you want to be able to access this token
- Leave All scopes selected
- Click Create Token
- Copy the token value and store it somewhere safe
We can test that we can connect to our VSTS account by using the login command. This will also allow us to avoid having to provide credentials on every command. Enter the following at the command prompt:
tfx login --authType pat
When prompted, enter your VSTS URL, including the collection, and press Enter. Now enter your Personal Access Token for your VSTS account and press enter. You should see a “logged in successfully” message. Now you can issue other commands to your VSTS account. For example:
tfx build tasks list
You will be presented with a list of every task associated with your VSTS account.
Now all you have to do is clone the GitHub repo and upload the task using the upload command:
tfx build tasks upload --task-path .\SwapDeploymentSlots
tfx build tasks upload --task-path .\SqlPackageTask
tfx build tasks upload --task-path .\WarConverter
In future posts, we will take a deep dive into writing VSTS tasks.