Jenkins参数释放与登台

时间:2019-01-17 17:12:05

标签: powershell jenkins substitution remote-execution

我在Jenkins中创建了一个我刚刚设置的自由式作业(最新版本)。

我向其中添加了参数。其中之一是ReleaseType的“选项”选项,其中包括“登台”和“发布”选项。

其中一个构建步骤是在将站点上传到服务器时在服务器上执行远程命令。它使用“执行Windows批处理命令”构建步骤。

这是命令行(具有通用功能):

sexec myuser@mysite.com -pw=mypassword -cmd="PowerShell -Command ""C:\batch\bvCopyFast.ps1 C:\inetpub\mysite${ReleaseType}\siteLoad C:\inetpub\mysite${ReleaseType}\site""

基本上,我正在执行一个Powershell命令,该命令使用Robocopy将文件从上载文件夹复制到站点的实际发布文件夹中。

如您所见,我需要将$ {ReleaseType}替换为实际值。问题是执行此操作时,它没有执行替换操作。我只是在命令中使用该文字值,但这不起作用。

1 个答案:

答案 0 :(得分:0)

如果使用-Co​​mmand参数,则意味着您将在后面的引号之间编写原始的PowerShell代码(允许您随时调用脚本)。

PowerShell -Command "Get-Date; pause;"

要调用PowerShell脚本文件,您应该使用:

PowerShell -File "Your-Script.ps1 -Parameter1 Argument1 -Parameter2 Argument2"

https://docs.microsoft.com/en-us/powershell/scripting/components/console/powershell.exe-command-line-help?view=powershell-6

我将编写一个接受您的根路径和releaseType作为参数的PowerShell脚本,然后执行该脚本。

Param($rootPath,$releaseType)
{
   robocopy "$($rootPath)\$($releaseType)\siteLoad" "$($rootPath)\$($releaseType)\site"  
}

我从未使用过詹金斯,所以我希望它能按我期望的那样工作!

sexec myuser@mysite.com -pw=mypassword -cmd=""PowerShell -File 'C:\batch\newScript.ps1' -RootPath 'c:\inetpub\mysite' -ReleaseType {ReleaseType}""