在我的Jenkins文件中,我有类似的东西:
def addDollar(param) {
return "\$" + param
}
parameters {
booleanParam(
defaultValue: false,
name: 'FORCE_UPGRADE'
)
}
environment {
FORCE_UPGRADE = addDollar(params.FORCE_UPGRADE)
}
stages {
stage('Test') {
steps {
powershell script: ".\\test.ps1 -forceUpgrade ${env:FORCE_UPGRADE}"
}
}
stage('Test Multiline') {
steps {
powershell script: '''
.\\test.ps1 `
-forceUpgrade $env:FORCE_UPGRADE
'''
}
}
}
powershell脚本是
param (
[Parameter(Mandatory=$true)][boolean]$forceUpgrade=$false
)
if($forceUpgrade) {
Write-Host "Forcing upgrade"
}
这个詹金斯阶段Test
可以正常工作,但是Test Multiline
出现了ParameterBindingArgumentTransformationException
错误:
Cannot process argument transformation on parameter 'forceUpgrade'. Cannot convert value "System.String" to type "System.Boolean". Boolean parameters accept only Boolean values and
numbers, such as $True, $False, 1 or 0.
如果运行,我会收到相同的错误
.\test.ps1 -forceUpgrade false
而不是.\test.ps1 -forceUpgrade $false
有什么想法可以使Jenkins Test Multiline
阶段发挥作用吗?我有一个脚本,需要传递多个args,非常适合防止使用多行powershell进行水平滚动
答案 0 :(得分:0)
将Powershell输入更改为[string]
而不是[boolean]
[string]$forceUpgrade = $false
在Powershell中的条件中,您仍然可以使用$forceUpgrade
变量作为布尔变量。