运行 Jenkins 的 Cygwin 脚本作为用户

Run Jenkins' Cygwin script as user

我在 Windows 上安装了 Jenkins 运行ning,并且我的构建在 CygWin 终端 bash 下运行良好,所以我现在想将其自动化。然而,使用这个脚本:

#!C:\cygwin\bin\bash.exe
whoami
make

系统将我报告为 nt authority\system,而不是我在使用交互式 shell 时得到的 ken。有没有一种简单的方法可以说服 Jenkins 或 CygWin 像我一样 运行?

您很可能运行正在使用默认安装的 jenkins。你有两个选择。首先在评论中提到。将 "Service account" 更改为与您的相同。

第二个选项来自 best practices. Run the jenkins master on a system with backup etc. Configure slave node 和您的帐户凭据。更改项目配置以在特定节点上构建。

(可以 运行 在同一台机器上使用不同的证书从属和主控 - 以防万一你想尝试一下)

我遇到的真正问题不是 shell 脚本 运行 宁作为错误的用户,而是 shell 脚本没有执行默认 /etc/profile.所以,解决方案很简单:

#!C:\cygwin\bin\bash.exe -l
whoami
make

我还是 nt authority\system,但现在我已经设置了正确的环境并且可以 运行 make 成功。

另请注意,如果我创建一个 /home/system 目录,我可以将 .bash_profile 等添加到该目录以进一步自定义构建环境。