Run Jenkins jobs on Linux under a User
Have a look at the Started-By Environment Variable plugin.
https://wiki.jenkins-ci.org/display/JENKINS/Started-By+Environment+Variable+Plugin
EDIT:
If you are just asking how to set up Jenkins to run under a different user in Linux it depends on how you installed it. I never set up Jenkins on Linux yet (but I can use google). Have a look at https://wiki.jenkins-ci.org/display/JENKINS/Installing+Jenkins for different setup options. I had a look at Installing Jenkins as a Unix daemon and at step 7 you need to setup a configuration file. Change the last line in that file (RUN_AS_USER=jenkins
) to contain the user of your choice.
Run jenkins job as another user
There is JENKINS_USER
variable in etc/default/jenkins
file. You could change it to ci_user, then you will need to change the ownership of several folders and reboot the machine.
chown -R ci_user /var/lib/jenkins
chown -R ci_user /var/log/jenkins
chown -R ci_user /var/cache/jenkins
Reference
How to run jenkins's job as a specific user?
Builds always run under the user that runs the node agent process. So your options are
- Specify a different user for connecting the node, or
- Switch to a different user during the build (e.g., via
sudo
in a shell build step). This is more flexible, but plugin related-code (like SCM checkout) will still run under the root account.
How to run Jenkins jobs as user other than anonymous?
I found it.
In Manage Jenkins -> Configure Global Security
, toward the middle of page there's a section called Access Control For Builds
. The Strategy
was set to Run as anonymous
, I set it to Run as SYSTEM
.
Run shell command in jenkins as root user?
You need to modify the permission for jenkins
user so that you can run the shell commands.
You can install the jenkins as as service (download the rpm package), You might need to change the ports because by default it runs http on 8080 and AJP on 8009 port.
Following process is for CentOS
1. Open up the this script (using VIM or other editor):
vim /etc/sysconfig/jenkins
2. Find this $JENKINS_USER
and change to “root”:
$JENKINS_USER="root"
3. Then change the ownership of Jenkins home, webroot and logs:
chown -R root:root /var/lib/jenkins
chown -R root:root /var/cache/jenkins
chown -R root:root /var/log/jenkins
4) Restart Jenkins and check the user has been changed:
service jenkins restart
ps -ef | grep jenkins
Now you should be able to run the Jenkins jobs as the root user and all the shell command will be executed as root
.
how to run a job on the master as a different user?
You can use su
or sudo
to run as a different user inside a build step, but that comes with some security implications. If this is something you want to do regularly I would recommend that you define a slave on the same machine with the other user, as you have suggested. I am not aware of any plugins/extensions that would make this easier for you unfortunately.
Related Topics
Critical Timing in an Arm Linux Kernel Driver
Accessing Linux /Dev/Usb as Standard Files to Communicate with Usb Device
How to Specify Time in Cron Considering Year
Determine Usb Device File Path
How to Get Ec2 Load Balancing Properly Set Up to Allow for Real Time File Syncing
Systemd: Start Service at Boot Time After Network Is Really Up (For Wol Purpose)
Interrupt Handling and User Space Notification
Get a Nanosecond-Precise Atime, Mtime, Ctime Fields for File (Stat)
How to Force Node.Js Require to Be Case Sensitive
Add Some Specific Time While Using the Linux Command "Date"
How to Keep Executable Code in Memory Even Under Memory Pressure? in Linux
Linux Terminal: How to Capture or Watch Other Terminal Session
Command to Zip a Directory Using a Specific Directory as the Root
Setting Up a Subdomain with Apache on Linux
How to Create a Hex Dump of File Containing Only the Hex Characters Without Spaces in Bash