Run jenkins jobs as different user or switch user during the execution

31 views
Skip to first unread message

Amit Chettri

unread,
Oct 7, 2020, 3:32:42 PM10/7/20
to Jenkins Users
Hello,

I have a requirement where I need to switch user in between in the pipeline run
:
:
steps
      {
        script
        {
       
            sh """
              sudo su - testuser
              whoami
            """
    :
    : 
    :
    }
 }

but during the pipeline run user is not switch and its still the jenkins user

+ sudo su - testuser

Last login: Thu Oct 8 00:35:26 IST 2020

+ whoami

jenkins

how can I run the job as a different user or switch user to testuser without making any change to $ sudo vim /etc/sysconfig/jenkins  

iris Jasper Orschulko

unread,
Oct 8, 2020, 9:05:53 AM10/8/20
to jenkins...@googlegroups.com
you could do something along the line of su testuser -c 'command to run as testuser'

From: jenkins...@googlegroups.com [jenkins...@googlegroups.com] on behalf of Amit Chettri [amitche...@gmail.com]

Sent: Wednesday, October 07, 2020 9:24 PM

To: Jenkins Users

Subject: Run jenkins jobs as different user or switch user during the execution

Reply all
Reply to author
Forward
0 new messages