Powershell 和 Jenkins - 以另一个用户身份执行 Powershell 脚本

标签 powershell authentication jenkins automation

我有一个由 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/

相关文章:

loops - 从 Powershell 的 ForEach 中返回一个值

excel - 复制粘贴 Powershell Excel 保留格式

asp.net-mvc - MVC 5 在 web.config 中自定义 OWIN 身份验证选项

github - 如何在 jenkins 中使用通用 webhook 触发器插件?

Jenkins 构建状态图标未显示在 github 中

node.js - 通过 Jenkins CI 在 Docker 容器中运行 Selenium 测试的最简单方法

powershell - Mercurial:自动添加子存储库的 Windows 脚本

PowerShell 复制项 : do I need a backslash at the end of my destination parameter?

azure - 为后台控制台应用程序选择身份验证提供程序

asp.net - 无需 cookie 即可跨多个域进行单点登录