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.
Please let me know if you have any suggestion.
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