Jenkins,构建执行 shell,在 ubuntu 上更改 shell 运行 用户

Jenkins, build execute shell, change shell running user on ubuntu

我正在尝试在我的 Ubuntu 服务器上设置 Jenkins。

$ sudo -u otherUser /bin/bash
$ whoami                  # I expected "otherUser" but show "jenkins"
$ start_build_script.sh   # This file will clones multiple remote repository 

但是当git克隆时,它的过程会失败,因为它是用“jenkins”用户克隆的。

jenkins@repo.com: Permission denied (publickey).
# The public key (for "otherUser") is already added to repo.com
# I want to clone as otherUser@repo.com

我知道为什么会发生这个错误,但遗憾的是我无法将“jenkins”用户添加到存储库站点。所以我必须使用“otherUser”用户。

我只能修改我的 ubuntu 服务器中的文件,但我不能修改远程存储库中的任何内容。

当 运行 构建脚本而不是“jenkins”时,如何将用户更改为其他用户?

您可以在 /etc/sysconfig/jenkins 中更改 JENKINS_USER,其中包含所有 jenkins 相关信息。

然后 shell 命令将 运行 与您的主人上的该用户。

如果运行在代理上连接,那么您可以配置应通过哪个用户代理连接。