0

I have setup a build server at the company I work for. This build server interactively works with Visual Studio Team Services.

Building works great and so does publish. The issue I am running in to is the ability to run "dotnet test" as a different user.

This is needed because currently the user the agent runs under is a service account. It has access to IIS and has the ability to move files where they need to be. But it does not have access to the database.

Since we have a few integration tests that we utilize, it errors out when connecting to the database because it is trying to connect as the service user.

So far I have not found a way to run "dotnet test" as a different user, specifically one that has access to query the database.

I tried utilizing the VSTS Task "Run Powershell on Remote Machines" since it lets me supply a username and password. But it seems to have issues trying to remotely connect to itself (which is probably understandable).

I am at a loss. I have no idea how to get this to work. Except giving the service user the ability to run those queries on the database.

Any help is greatly appreciated!

2 Answers 2

3

SQL authentication is the better way. So change connectionstring to use SQL authentication.

Server=myServerName\myInstanceName;Database=myDataBase;User Id=myUsername;
Password=myPassword;

Authentication article: Choose an Authentication Mode

2
1

You could start a process with the desired identity by passing appropriate credentials, e.g.

param($user, $pwd)
Start-Process $DOTNET_TEST_COMMAND -WorkingDirectory $DESIREDCURRENTWORKINGDIR -Credential (New-Object System.Management.Automation.PSCredential -ArgumentList @($user,(ConvertTo-SecureString -String $pwd -AsPlainText -Force)))

My opinion is that during a build only unit tests should be executed, as you could have side effects on the shared build machine if you execute more convoluted tests as functional tests. Instead than running the functional tests on the build machine, I would suggest to use the Run Functional Tests task during a Release of VSTS, as it would allow you to:

  • distribute the tests on a pool of machines where you installed the test agent by means of the Deploy Test Agent task);
  • provide the credentials of the identity the tests run for, this functionality is present out of the box in the task, i.e. solve your problem at the root;
1
  • The idea of run functional tests is really a great one. I wish I could mark these both as answers. They are both vital to my question.
    – kyurthich
    Commented Jan 9, 2017 at 18:10

Not the answer you're looking for? Browse other questions tagged or ask your own question.