sudo su with password provided in jenkins?

5,682

Really the best way to do this would be to ask your Jenkins administrator to add sudoers permissions to allow Jenkins to login and run commands as the other user.

Beyond that, your best bet would be to store the username and password in Jenkins' built-in credentials store and use the withCredentials step in your Jenkinsfile to authenticate as the other user.

Share:
5,682

Related videos on Youtube

sp_devops
Author by

sp_devops

Updated on September 18, 2022

Comments

  • sp_devops
    sp_devops over 1 year

    I am stuck with one requirement in which I am switching to some "xxx" user and it asks for password every time. I am trying to automate this process with password hardcoded in Jenkins job. ex: sudo su - "xxx" password should be given in Jenkins job

    Can anyone provide some solution code?

    Thanks, sp_devops

    • sp_devops
      sp_devops over 5 years
      I don't have root access so sudoers will not work.
  • sp_devops
    sp_devops over 5 years
    Thanks @jayhenden.. I would really appreciate if you could provide me the cli for using the withcredentials step..
  • jayhendren
    jayhendren over 5 years
    You can get instructions on how to use it by following the link I posted.