我有一个由 Jenkins 服务器、几个 Jenkins Slaves (windows) 和几台远程 Windows 计算机组成的环境,它们都属于同一域。
我需要运行一个 jenkins 作业,它针对同一域中的其他 Windows 远程计算机(未安装模块)执行由多个函数(加载到 Jenkins Slave 的自定义模块的一部分)组成的 powershell 片段.
这些模块需要在具有访问远程计算机权限的特定域帐户下运行。
如果我使用任何 jenkins slave(使用该特定域帐户)登录,一切正常。
默认情况下,Jenkins 使用 NT authority\system 帐户在从服务器上执行作业,当然,这会返回拒绝访问错误。
问题:有没有办法告诉 Jenkins 使用另一个特定域帐户而不是 NT Authority\System 帐户在 windows slave 上执行作业?
已经尝试过:
使用凭据调用命令:这不是一个选项,因为远程计算机没有这些模块
模仿:尝试了 PS 画廊中的几个功能,但不起作用
最佳答案
您可以在脚本中将 powershell 作为进程运行,并从 Jenkins 调用它。在脚本中你也可以使用像:
$username = 'username'
$password = 'password'
$securePassword = ConvertTo-SecureString $password -AsPlainText -Force
$credential = New-Object System.Management.Automation.PSCredential $username,$securePassword
Start-Process Powershell.exe -Credential $credential
希望对您有所帮助。
关于Powershell 和 Jenkins - 以另一个用户身份执行 Powershell 脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51857709/