简体   繁体   English

Powershell 命令手动工作,但在 Jenkins 中执行时不起作用

[英]Powershell command works manually, but does not work when executed in Jenkins

I'm having a strange scenario where my command works on PowerShell manually but not when executed on Jenkins PowerShell plugin.我有一个奇怪的场景,我的命令手动在 PowerShell 上运行,但在 Jenkins PowerShell 插件上执行时却不行。 I'm new to PowerShell and Jenkins and I'm thinking that there's a rule I'm missing.我是 PowerShell 和 Jenkins 的新手,我想我缺少一条规则。 I looked all over the here and net but I failed to find the solution.我在这里和网上到处找,但我没有找到解决方案。

I created a job that executes a PowerShell script that opens an RDP file on my desktop using a freestyle project.我创建了一个执行 PowerShell 脚本的作业,该脚本使用自由式项目在我的桌面上打开一个 RDP 文件。 It works as expected when executed on Powershell but in Jenkins, the build succeeds but it did not open the RDP.在 Powershell 上执行时,它按预期工作,但在 Jenkins 中,构建成功,但没有打开 RDP。

Here's the script:这是脚本:

Start-Process "$env:windir\system32\mstsc.exe" -ArgumentList "RDP File /h:900 /w:1600" -WindowStyle Minimized

I'm using Windows Server 2016.我正在使用 Windows 服务器 2016。

Here's what I tried:这是我尝试过的:

  1. By default Jenkins uses 32-bit PowerShell, so I manually used the 64-bit but it didn't work.默认情况下 Jenkins 使用 32 位 PowerShell,所以我手动使用了 64 位,但它不起作用。
  2. I made sure that Get-ExecutionPolicy is set to RemoteSigned on LocalMachine我确保 Get-ExecutionPolicy 在 LocalMachine 上设置为 RemoteSigned
  3. Run the script using Windows Batch Command使用 Windows 批处理命令运行脚本
  4. I tried opening notepad but it does not work too.我尝试打开记事本,但它也不起作用。

Is this really the behavior of the PowerShell plugin?这真的是 PowerShell 插件的行为吗? Is there any points that I'm missing?有什么我遗漏的地方吗? Kindly help me with this.请帮我解决这个问题。

To anyone might need this.任何人都可能需要这个。 I was able to execute the RDP via Jenkins PowerShell plugin.我能够通过 Jenkins PowerShell 插件执行 RDP。

What I did was to go Jenkins' Window Service > Log on tab > Select "This account" and enter your user account credentials.我所做的是 go Jenkins 的 Window 服务 > 登录选项卡 > Select “此帐户”并输入您的用户帐户凭据。

I suspect this is a security issue.我怀疑这是一个安全问题。 Jenkins by default is using the "SYSTEM" account which does not have enough privileges. Jenkins 默认使用没有足够权限的“SYSTEM”帐户。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 命令直接在 Powershell 中工作,但在使用 powershell 通过 linux 系统执行时不起作用 - Command works directly in Powershell but doesn't work when executed through a linux system using powershell Powershell Invoke-Command 远程手动工作,但不是来自 Jenkins - Powershell Invoke-Command remote works manually, but not from Jenkins AWS Systems Manager 命令:手动执行时有效,运行命令无效 - AWS Systems Manager Command: Works when executing manually, does not work from run command Powershell 从 dockerfile 运行时找不到文件,但在容器内手动执行时有效 - Powershell cannot find file when run from dockerfile, but works when manually executed inside container Powershell命令输入CMD时不起作用 - Powershell command does not work when inputed into CMD invoke-command 从 powershell 工作,从 cmd window 调用 powershell 不工作 - invoke-command works from powershell, does not work from a cmd window invoking powershell powershell:在循环内调用时命令不起作用 - powershell : command does not work when called inside a loop Jenkins PowerShell:在 Jenkins 但不在 Z3D265B4E03EEEF0DDF178B181FA 中执行时,使用 Passthru 的启动进程返回不同的进程 ID - Jenkins PowerShell: Start-Process with Passthru returns a different process ID when executed in Jenkins but not on PowerShell Jenkins 注入环境变量适用于批处理命令,但不适用于 powershell - Jenkins Inject Environment variable works with batch command but not powershell 从VBA调用时,PowerShell命令不起作用,但其他方式有效 - PowerShell command doesn't work when called from VBA, but otherwise works
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM