How can I run a MsBuild job as a different user?

Article ID:360033180952
1 minute readKnowledge base


I want to be able to run MsBuild jobs using a user different from the user running the agent process.


In order to be able to cover this use case, you will only need to add the user name and the password as parameters as mentioned in the [plugin page]((

The syntax should be the one supported by MsBuild to add these kind of parameters /P:Username=myuser;Password=mypassword you can get additional details on how to pass username and password safely in the following Microsoft Forum post. But please, be aware that you should not use passwords in the command line please check also Injecting Secrets into Jenkins Build Jobs for additional techniques to avoid using passwords in a non secure way.

Important Notice:

Please, be aware that any special character included in your username or password should be escaped, otherwise you will get an error during the job execution.

One easy way to rule out if your problem is related to this is to use a user/password combination that does not include any special character.