How to Run a Root-Level Shell Script in Jenkins

How to Run a Root-Level Shell Script in Jenkins

Jenkins normally runs shell commands as the jenkins user. However, some server-maintenance tasks require root privileges—for example, cleaning APT caches, removing old packages, or managing system files. A common but unsafe approach is to give the Jenkins user unrestricted sudo access: jenkins ALL=(ALL) NOPASSWD: ALL This allows Jenkins jobs to execute arbitrary commands as root. A much safer approach is to allow Jenkins to run only one specific maintenance script as root....