How to register capabilities on your build and release management agents

To run Selenium test against different browsers using our new build and release systems the browser must be installed on the agent machine.  The question is how can we identify which agents have which browsers.  Our new build and release systems use the same agents and the agents let you identify agent capabilities.


You can add a user capability but you have to do this for each agent.  If you installed 8 agents on the same machine you would have to add the same capability to each of the 8 agents.  However, there is a way to register a capability to the machine that all the agents will automatically pick up.  For example if you wanted to identify that you had version 44 of Chrome installed on a machine you can simply define a System Variable.


After doing so, restarting your agents will have each of them automatically pick up new capability.


Now you can define Chrome as a demand on your build or release and only agents that have the Chrome capability will be selected to execute the build or release.

Comments (26) -

  • Anthony Terra

    9/27/2015 3:32:57 PM | Reply

    Great Post Donovan, I was at Build 2015 when you demonstrated some of these features.  This Environment variable setting is very helpful.  One thing I am curious about.  I noticed that some of the demands are coming from a location other than Environment variables.  If I were to say install software on the machine, is there another location I could use to add the "demand" to the system?  I would prefer not to have some persnickety sys admin decided to clean up the Environment Variables one day and screw my demands up.

    Thanks again, great work on the new TFS

    • Donovan

      10/7/2015 3:05:09 PM | Reply

      Sorry for the delay. You can use the User capabilities section on the Agent pools page from the Administration pages of your VSO account.  That way only VSO administrators can control the capabilities.

  • Jeppe Agger

    2/8/2016 1:25:46 PM | Reply

    Thanks for a great post.

    Sorry for being late to the party, but I have a question regarding User Capabilities. According to this page: msdn.microsoft.com/.../configure-agents (see the description of User Capabilities), it's possible to use User Capabilities to specify paths for tools on a specific agent. I can't find any other documentation about this and I can't get it to work, so I'm wondering how I do this?

    • Donovan

      2/28/2016 1:22:47 AM | Reply

      Trying to track down an answer.

      • Robin Paardekam

        4/13/2016 1:39:50 PM | Reply

        I'm also struggling with this: I have user capabilities specifying the local path of a specific tool, which can vary per agent. Now all I need is a way to get that path exposed but I haven't found the solution yet.

        • Diego

          4/7/2017 1:09:31 PM | Reply

          Have you solve this problem?

      • TFSUser

        5/6/2016 9:57:39 AM | Reply

        I believe there is a bug here, unless i'm missing something.  on-prem tfs 2015 update 2.  if you create user capability for a agent then I cannot use that value in the builds.  for example, under hosts > agent I created a user capability called "PathtoXYZ" and when I tried to use this in by build $(PathtoXYZ) it would not be found.  even tried restarting the agent. no luck. Frown

  • Vince Sam

    11/4/2016 4:12:16 PM | Reply

    Hi Donovan,
    We updated java home path in a Linux agent but the Agent is not picking that change - it is still referencing the old version.  The agent was re-started but this did not solve it.  Any thoughts?
    Vince

    • Donovan

      11/5/2016 3:29:18 PM | Reply

      Stop the agent
      cd to agent folder
      delete .env
      run env.sh

      You should get a new .env

      start agent.

  • Vaughn Hughes

    11/16/2016 9:35:49 PM | Reply

    I have specified an agent-specific value as a User Capability which I want to retrieve during a build as a variable. The VS documentation (www.visualstudio.com/.../configure-agents) implies that this is possible, but no variable or value exists when the build is running. (I'm using TFS 2015 Update 3) Am I missing something here? How do I access the User Capability name/value pairs from within steps in my build? Thanks.

    • Donovan

      11/17/2016 8:48:37 PM | Reply

      I think they are in env vars.

  • Anup Manekar

    4/4/2017 10:45:53 AM | Reply

    Hi Donovan,

    I dont see option of restarting a hosted agent. I just added Chrome in User Capabilities. Is this something to do with free account?

    Thanks
    Anup

  • Anup Manekar

    4/4/2017 11:27:57 AM | Reply

    ok, update - I have installed private agents and have better control.

  • Jeeva

    6/26/2017 1:30:14 PM | Reply

    Hi Donovan,

    We are building a xamarin.android project using VSTS build definition. For signing the apk file we use a KeyStore file and we wanted to be very secure in storing the file. We have an on premise Mac build agent configured and decided to place the file in some location and reference the path in the build definition to pick the KeyStore file. It works with the hard coded absolute path but we would like to add this as a capability in the build definition then reference using the capability. Is that possible? Please advice.

    Thanks
    J

  • Kirsten Kluge

    8/23/2017 7:45:13 AM | Reply

    Hi Donovan,

    I can not get this to work on linux Agents. set Env variables bevor register the agent but none of my values showed up in the list on my TFS Server.
    I did not find any documentation abut this.

    Many Thanks,
    KirK

    • Daan

      11/23/2018 3:29:13 PM | Reply

      There is a env.sh script in the agent.tar, you have to add your capability to the list in that script to have it show up as capability.

  • Syed Hassan Abbas

    9/4/2017 11:47:35 AM | Reply

    I can set demands in build definition but how do we set it in release definitions? is picking the agent based on capability not available for releases?

  • Marcus Felling

    1/9/2018 7:44:13 PM | Reply

    Donovan,

    Is it possible to set a user capability programatically (PowerShell preferred)? I'd like to add this to our build server Infrastructure as Code.

    Thank you in advance,
    Marcus

  • Mahesh Shabad

    7/26/2018 7:46:12 PM | Reply

    Donovan,
    I have a containerized build agent running in AKS cluster which is linked to my agent pool in VSTS, how ever that agent is missing some capabilities , the base image I am using in my Dockerfile is ubuntu, can you help me how can i add capabilities in the containerized VSTS agent?? please

    Thank you in advance,
    Mahesh

    • Donovan

      8/7/2018 8:35:08 PM | Reply

      I would pass in environment var values when you start your container. They should then show up as capabilities.

  • Rohit

    9/5/2018 3:59:27 PM | Reply


    Im getting the below error while executing  "install npm " in VSTS 2015 build definition?
    Error: "No agent could be found with the following capabilities: npm ".
    Is there any way  to add capability for npm in VSTS 2015?

  • John Seghers

    9/11/2018 1:57:29 AM | Reply

    Hi Donovan,
    I need to do the opposite of what you are doing in this article. I need to have capabilities set on a per-agent basis even it the agents are running on the same machine. I see how to do that through the UI for build agents (Organization Settings->Agent pools->select agent->select Capabilities->Add Capability) but I don't see the same ability for a Deployment agent.
    Organization Settings->Deployment pools->select agent seems to show a read-only list of capabilities.

    Is there something I'm missing?

  • Maciej

    10/16/2018 9:52:24 AM | Reply

    Hi
    We can set new capabilities but how can i read those?
    In my case i need to assign each agent a target machine so that 2 agents dont restore same machine.
    Or maybe there is another way of doing thaT?

    • Donovan

      10/29/2018 4:46:39 PM | Reply

      They are just stored as environment variables. So however you read those with your language you are using should work.

      • Maciej

        10/29/2018 5:06:47 PM | Reply

        Tried that, I am able to read any agent capability as env variable with PowerShell, but user defined ones are not accessable, always empty. Although they are seen by the agent requirements so I can ensure that only agent with MySpecialCapability is assigned to this build but i cant read it in powershell Smile or I am doing something wrong Frown....

        • Jeff

          11/14/2018 7:24:06 PM | Reply

          I found the same behavior. If i set a value for an agent in TFS under User Capabilities, this did not create an environment variable on the agent system that could be used later in the process.

          What I ended up doing, was setting the capability as a System Variable on the agent machine, and then adding a powershell task:

          Write-Host "##vso[task.setvariable variable=VariableName;]$env:VariableName"

          This populated a variable that could be used by TFS.

Pingbacks and trackbacks (4)+

Add comment

Loading