简体   繁体   English

使用Jenkins的PowerShell脚本重置远程IIS

[英]Reset Remote IIS with PowerShell script from Jenkins

I have a PowerShell script which connects to remote server and resets the IIS, this script works fine if i execute it from PowerShell window, my problem is getting it work with Jenkins, I have tried few options as below. 我有一个连接到远程服务器并重置IIS的PowerShell脚本,如果我从PowerShell窗口执行该脚本,该脚本可以正常工作,我的问题是使它与Jenkins一起使用,我尝试了以下几种方法。

Using Exec Ant task in my build script: 在我的构建脚本中使用Exec Ant任务:

<target name ="reset.IIS" description="Resets the IIs of specified URL">
    <exec executable="powershell" failonerror="true" outputproperty="myscript.out" errorproperty="myscript.error" output="iisout.log">
        <arg line="-ExecutionPolicy RemoteSigned" />
        <arg line="-File ${script.path}" />
    </exec>
<if>
    <not>
        <equals arg1="${myscript.error}" arg2="" trim="true" />
    </not>
    <then>
        <fail message="${myscript.error}" />
    </then>
</if>
</target>

This is my PowerShell script: 这是我的PowerShell脚本:

Import-Module WebAdministration
Set-ExecutionPolicy Remotesigned
$User = "MYComputer\User"
$File = "E:\Temp\Password.txt"
$targetServer  = "AA140294"
$MyCredential=New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $User, (Get-Content $File | ConvertTo-SecureString)

Invoke-Command -ComputerName $targetServer -ScriptBlock{ D:\Trunk\build\sprint17qcReset.ps1 } -Credential $MyCredential

When I run this from Jenkins nothing happens; 当我从詹金斯(Jenkins)运行此程序时,什么也没发生 it will just show executing script in console window. 它只会在控制台窗口中显示执行脚本。

I also tried moving it out from build script and putting it inside a build step in Jenkins "Windows powershell", but I get the following error: 我还尝试将其从构建脚本中移出并将其放入Jenkins“ Windows powershell”中的构建步骤中,但是出现以下错误:

[JenkinsCI] $ powershell.exe "&       'C:\Windows\TEMP\hudson7326095447547431161.ps1'"
File C:\Windows\TEMP\hudson7326095447547431161.ps1 cannot be loaded because the
execution of scripts is disabled on this system. Please see "get-help
about_signing" for more details.

This is my ps1 script in remote computer: 这是我在远程计算机上的ps1脚本:

Import-Module WebAdministration
$name = "build.test.com"
$path = "IIS:\Sites\"
$fullpath = $path + $name
Stop-Webitem $fullpath
Start-Webitem $fullpath
Get-Website -Name $name
Exit-PSSession

I checked Execution policy from PowerShell window. 我从PowerShell窗口检查了执行策略。 It's Unrestricted. 没有限制。

Any help is appreciated, Thanks in advance. 任何帮助表示赞赏,在此先感谢。

您应该将执行策略设置为不受限制地进行测试。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM