问题
I am trying to get Jenkins to run jobs as specific linux Users.
I have set security to use Unix authentication and installed the "Authorize Project" plugin.
I have written a simple script in my ~/bin
directory that sends me an email with the message "Hello $USER".
In Jenkins I set up a job and use the Authorize Project plugin to select run as specific user
and my username.
When I try to create a build the job fails. If I look at the output console the messages say that the job has been started by my user, that the job has been run by me. But then the job fails because the script is actually run by user jenkins
which doesn't have all the required permissions (nor environment variables set).
Am I doing something wrong? How can I fix this?
回答1:
The "Authorize Project" plugin does not change the OS level user that is running commands. It only sets the Jenkins user that is running the job and any downstream jobs, using Jenkins authentication (whatever it might be).
For example: Job A can be run by user Alpha and Beta, Job A runs Job B, and Job B can only be run by Alpha.
Normally, Alpha or Beta can run Job A, which will run Job B no problem, because Job B would be run as the System User by default.
But in some situations, maybe you want to enforce that Beta cannot run Job B, regardless of how they start the process. So Job A could be set to "Run as the user who triggered the build". When Beta runs Job A, Job A won't be able to run Job B, since the enforced user is Beta and Beta can't run Job B.
Or the reverse: Beta isn't allowed to run Job B directly. But if they run some specific process (run Job A), then they can run Job B indirectly. Setting Job A to "Run as the specified user" and specifying a user (such as Alpha) that can run Job B will allow Beta to run Job B via Job A.
来源:https://stackoverflow.com/questions/34063936/jenkins-run-as-specific-user-not-working