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

Article ID:360033180952
1 minute readKnowledge base

Issue

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

Resolution

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]((https://plugins.jenkins.io/msbuild).

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.

This article is part of our Knowledge Base and is provided for guidance-based purposes only. The solutions or workarounds described here are not officially supported by CloudBees and may not be applicable in all environments. Use at your own discretion, and test changes in a safe environment before applying them to production systems.