How to run or install tool on hosted agent in VSTS

2020-06-23 07:52发布

I want to run cmd as an administrator on VSTS.

Actaully I am trying to install git-tfs with chocolatey tool manager on VSTS hosted agent, So I am running the following command on VSTS command line task:

@"%SystemRoot%\System32\WindowsPowerShell\v1.0\powershell.exe" -NoProfile -InputFormat None -ExecutionPolicy Bypass -Command "iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))" && SET "PATH=%PATH%;%ALLUSERSPROFILE%\chocolatey\bin"

or,

Alternatively VSTS also provides the chocolatey task for installation, you can see this in the screenshot :

enter image description here

Both of the above approaches giving the same error:

[error]System.Management.Automation.RuntimeException: Installation of Chocolatey to default folder requires Administrative permissions. Please run from elevated prompt. Please see https://chocolatey.org/install for details and alternatives if needing to install as a non-administrator. ---> System.Management.Automation.RuntimeException: Installation of Chocolatey to default folder requires Administrative permissions. Please run from elevated prompt. Please see https://chocolatey.org/install for details and alternatives if needing to install as a non-administrator.

2条回答
爱情/是我丢掉的垃圾
2楼-- · 2020-06-23 08:35

I have just done a quick test which was the following:

  1. Set up a VSTS Build using Hosted 2017 Build Agent
  2. Added PowerShell Task with the following contents

    choco list --local-only

  3. Ran the build

This command correctly output the list of Chocolatey Packages that are currently installed via Chocolatey.

This tells me that Chocolatey is already installed on the Hosted 2017 Build Agent, and as a result, you shouldn't need to install it again. Instead, you should be able to install additional applications using it.

NOTE: The packages that you try to install will still be subject to the same permissions though. So if you are trying to install an application that requires administrative permissions, then you will likely run into the same problems.

查看更多
姐就是有狂的资本
3楼-- · 2020-06-23 08:37

You generally can't. If something requires admin access and you're using the hosted agent, you can't do that thing.

For your specific problem, I'd start by looking at this resource, which the error message gave to you:

"Please see https://chocolatey.org/install for details and alternatives if needing to install as a non-administrator."

查看更多
登录 后发表回答