Jenkins 管道无法 运行 Jenkins 节点上的远程脚本

Jenkins pipeline fails to run a remote script on a Jenkins node

我正在尝试 运行 以下清理脚本,但它在特定的 Jenkins 节点上一直失败:

def BUILDERS = [:].asSynchronized()
def NODE_NAMES = [
    'cleanuptooldean', //test
    ]

node('master') {
    stage('Prepare the Pipeline') {
        // get deploy pattern from params 
        for (NODE_NAME in NODE_NAMES) {
            // Groovy closures stuff, need to copy it over
            def FINAL_NODE_NAME = NODE_NAME
            BUILDERS[FINAL_NODE_NAME] = {
                node(FINAL_NODE_NAME) {
                    timeout(time:5, unit: "MINUTES") {
                        echo "Started Cleaning process of unused docker images from Jenkins Instance, Agent: "+env.NODE_NAME
                        sh "docker system prune -a --volumes -f"
                        echo "Cleaning up space from unused packages (orphaned dependencies), remove old kernels in Ubuntu, Agent: "+env.NODE_NAME
                        sh "sudo apt-get -y autoremove --purge"
                        echo "clean the apt cache on Ubuntu "+ env.NODE_NAME 
                        sh "sudo apt-get -y clean"
                        echo "Finished Cleaning process of unused docker images from Jenkins Instance, Agent: "+env.NODE_NAME
                    }
                }
            }
        }
    }
}

如果我在 "apt-get -y autoremove --purge""apt-get -y clean" 是:"sudo: 不存在 tty 且未指定 askpass 程序" 不用说我已经编辑了 sudoers 文件并添加了 "jenkins ALL=(ALL) NOPASSWD: ALL" 以便在文件末尾对其进行测试。 如果我删除“Sudo”命令,我得到的错误是:"dial unix /var/run/docker.sock: connect: permission denied" 我试图通过添加“Jenkins”来解决" 用户添加到“docker”组。

** 我必须说,当我 运行 在本地使用和不使用“Sudo”命令时,它们都可以从“Jenkins”用户使用,但是当我尝试使用管道从 Jenkins 远程执行它时失败。

***这个特定的脚本在其他节点上完美运行

提前致谢

显然每个节点使用不同的用户,所以我必须将所有用户添加到 docker 的组并将它们添加到 visudo 文件中。