无法在Jenkins上运行PowerShell

时间:2018-07-19 10:17:08

标签: powershell jenkins

我正在运行PowerShell脚本,该脚本将停止远程计算机上的服务。当我在PowerShell ISE中运行它时,它运行良好。但是,当我尝试从本地计算机上托管的Jenkins运行它时,出现了错误。

$SQL_agent="SQLSERVERAGENT"
$SQL_server="MSSQLSERVER"
$SQL_Agent_Service = Get-Service -Name $SQL_agent -ComputerName 192.168.48.44
$SQL_Server_Service = Get-Service -Name $SQL_server -ComputerName 192.168.48.44
 Stop-Service -InputObject $SQL_Agent_Service
  log("[SQLSERVERAGENT] shutdown complete.");
  Stop-Service -InputObject $SQL_Server_Service
  log("[MSSQLSERVER] shutdown complete.");

从jenkins运行该错误时(我的本地计算机上正在运行jenkins),

<pre>
D:\Eclipse_Repository\self_repo\jmallick\remote_db_backup.ps1:42 char:22
+ ... ent_Service = Get-Service -Name $SQL_agent -ComputerName 192.168.48.44
+                   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (SQLSERVERAGENT:String) [Get-Ser 
   vice], ServiceCommandException
    + FullyQualifiedErrorId : NoServiceFoundForGivenName,Microsoft.PowerShell. 
   Commands.GetServiceCommand
Get-Service : Cannot find any service with service name 'MSSQLSERVER'.At 
D:\Eclipse_Repository\self_repo\jmallick\remote_db_backup.ps1:43 char:23
+ ... er_Service = Get-Service -Name $SQL_server -ComputerName 192.168.48.44
+                  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (MSSQLSERVER:String) [Get-Servic 
   e], ServiceCommandException
    + FullyQualifiedErrorId : NoServiceFoundForGivenName,Microsoft.PowerShell. 
   Commands.GetServiceCommand
</pre>

对此有何想法?

1 个答案:

答案 0 :(得分:0)

Jenkins的运行帐户似乎与MSSQLSERVER不在同一帐户上 更改jenkinsMSSQLSERVER服务的帐户

  • 关注服务
  • 右键单击Jenkins服务,然后选择属性
  • 转到登录标签
  • 点击此帐户
  • 在浏览对话框中,选择要在其中运行Jenkins或数据库服务器的用户帐户