Runbuild steps as a different user in Jenkins

I use a centralized jenkins setup that is used to build projects for different groups. The jenkins is run as user u1. Some of test cases in different projects require some permission that is granted only to group specific user u2, u3 etc. I want to run the test cases as u2 from my jenkins.

How in Jenkins can I run the maven/ant target as a different user than jenkins run user.
I do not want to launch a slave node as u2 because that can run any command than just the test command.

  • How to stop an unstoppable zombie job on Jenkins without restarting the server?
  • Jenkins Pipeline - SVN polling
  • Jenkins CI: How to trigger builds on SVN commit
  • How can we execute Jenkins job using other user credential
  • Read file from Jenkins workspace with System groovy script
  • How can Jenkins poll on a specific file and not the whole repo
  • Please let me know if you have any suggestion.

    Thanks

  • How to create jenkins credentials via the REST API?
  • How to receive local Git branch name with Jenkins Git plugin?
  • How to resolve stderr: fatal: Not a valid object name HEAD in jenkins?
  • Jenkins: How To Build multiple top-level projects from a git repository?
  • getting NuGet to work both with whole solution and individual projects included in it
  • Getting exception while configuring the maven project in jenkins
  • One Solution collect form web for “Runbuild steps as a different user in Jenkins”

    It depends on the OS. You won’t be able to run the maven/ant target using the maven/ant plugin in jenkins, since it uses whatever user the jenkins slave is running under. You would have to run a build step of type “Execute shell script” Or “Execute windows batch command” In your batch file, you would need to use

    runas /user:<machine>\u2 ant <target>

    or on linux

    su -c "ant <target>" u2

    Git Baby is a git and github fan, let's start git clone.