首页 > 解决方案 > Jenkins,构建执行 shell,在 ubuntu 上更改 shell 运行用户

问题描述

我正在尝试在我的 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”时,如何将用户更改为其他用户?

标签: jenkins

解决方案


您可以/etc/sysconfig/jenkins在所有 jenkins 相关信息存在的地方更改 JENKINS_USER。

然后 shell 命令将在您的主服务器上与该用户一起运行。

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


推荐阅读