Run shell command in jenkins as root user?

后端 未结 5 637
梦毁少年i
梦毁少年i 2020-12-08 01:42

I have recently started using Jenkins for integration. All was well until I was running jobs on master node without shell command but I have to run jobs on master as well as

5条回答
  •  难免孤独
    2020-12-08 01:57

    I would suggest against running the jenkins user as root. This could expose the operating system and all of the repo's which jenkins can build.

    Running any script as root is a security risk, but a slightly safer method would be to grant the jenkins user sudo access to only run the one script, without needing a password.

    sudo visudo
    

    and add the following:

    jenkins    ALL = NOPASSWD: /var/lib/jenkins/jobs/[job name]/workspace/script
    

    Double check your path via the console log of a failed build script. The one shown here is the default.

    Now within the jenkins task you can call sudo $WORKSPACE/your script

提交回复
热议问题