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

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

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

Amit Chettri
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  

--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/f40da188-c4c2-4bf3-99a3-134ca4f65180n%40googlegroups.com.
Reply | Threaded
Open this post in threaded view
|

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

iris Jasper Orschulko
you could do something along the line of su testuser -c 'command to run as testuser'



From: [hidden email] [[hidden email]] on behalf of Amit Chettri [[hidden email]]

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

To: Jenkins Users

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





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  



--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/38B822B13B092D4C832A97382607EFDF07CFA3AD%40ERDE.irisgmbh.local.