首页 > 解决方案 > 该字符串缺少终止符:“。powershell jenkins

问题描述

尝试自动化 powershell 行时遇到一个奇怪的问题。

在我的 powershell 上它可以工作,但在 Jenkins 管道下它总是说以下错误:

The string is missing the terminator: ".
+ CategoryInfo          : ParserError: (:) [], ParentContainsErrorRecordException
+ FullyQualifiedErrorId : TerminatorExpectedAtEndOfString

我的代码行:

powershell $mybranch = (get-content F:\software\branchname) -replace '.*?/'; new-Item -ItemType Directory -Force -Path "\\myserver\sw\software\rs\2020-RC1_$branchname"; copy-item -path "E:\Temp\2020-07-22_1.1.1-RC1_$branchname.zip" -destination "\\myserver\sw\software\rs\2020-RC1_$branchname\"

标签: powershelljenkinsgroovy

解决方案


它是双引号之前的尾随反斜杠… -destination "\\myserver\sw\software\rs\2020-RC1_$branchname\"。加倍。

例子:

powershell -noprofile dir "packages\"
The string is missing the terminator: ".
    + CategoryInfo          : ParserError: (:) [], ParentContainsErrorRecordException
    + FullyQualifiedErrorId : TerminatorExpectedAtEndOfString
powershell -noprofile dir "packages\\"
    Directory: D:\bat\packages


Mode                 LastWriteTime         Length Name
----                 -------------         ------ ----
d-----        01.06.2020     10:41                com.company.sft

推荐阅读