How Do I Upload a Custom Task for Build?

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:

npm

image

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:

tfx
image

To connect to your VSTS account you are going to need a Personal Access Token.

  1. Log into VSTS
  2. Click your name in the upper right-hand corner
    image_thumb[15]
  3. Click My security
  4. Click Add under Personal access tokens
  5. Give the access token a name
  6. Select how long you want the token to be valid
  7. Select the accounts you want to be able to access this token
  8. Leave All scopes selected
  9. Click Create Token
  10. Copy the token value and store it somewhere safe
    image_thumb4_thumb

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.

Comments (5) -

  • Denise

    2/5/2016 11:58:42 PM | Reply

    Hi, I am trying to do this but I am getting the following error when uploading: "403 - Access denied - [user] needs manage permissions to perform action."

  • Denise

    2/5/2016 11:59:17 PM | Reply

    Do you know which permissions do I need for this?

    • Donovan

      2/28/2016 1:17:53 AM | Reply

      Are you the owner of the VSTS account?

  • Andreas

    9/20/2019 12:23:54 PM | Reply

    Hi Donovan. Thanks for the post. Is the Full Scope really necessary? I tried it with packaging "read,write,manage" and it didn't work, but I am not sure if a full scope should be the answer. Any ideas? Thanks Smile

  • Andreas

    9/26/2019 7:59:31 PM | Reply

    Your PAT should have "Deployment Group" permission (Read/Manage). And you should be administrator of the Agent Pool (if you are collection admin, then this is already done for you)

Pingbacks and trackbacks (1)+

Add comment

Loading