【问题标题】:passing multiline string parameter in powershell using jenkins使用jenkins在powershell中传递多行字符串参数
【发布时间】:2021-09-16 21:09:57
【问题描述】:

我正在尝试通过 jenkins 运行 powershell 脚本。但在传递多行字符串时遇到问题。

$content = @"
test1
test2
test3
"@
Add-content filepath $content 

上面的脚本是通过 jenkins 运行的,但是内容被保存在一行中。例如

test1test2test3

但我想以下面的方式保存它-

test1
test2
test3

任何解决方案我怎样才能将内容保存在上面提到的不同行中。

【问题讨论】:

  • 这似乎是目标文件的编码问题...

标签: powershell jenkins jenkins-plugins powershell-2.0 powershell-3.0


【解决方案1】:

我不确定我是否正确理解了您的问题,但希望这会有所帮助...

输入(作为数组)=

$content = @("test1","test2","test3")
$content

输出=

test1
test2
test3

Finished: SUCCESS

或者你可以使用(如果你使用多行字符串参数):

$content =$content |foreach-object {$_.split(' ')}

这会将变量分成几行

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-10-22
    • 2010-09-06
    • 1970-01-01
    • 1970-01-01
    • 2015-08-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多