我想在 power shell 脚本中使用 jenkins 环境变量。这里 ${destination} 在 powershell 脚本中为 null。无法识别我在做什么错误。请帮助
# !/bin/groovy
pipeline {
agent {
label {
label ""
customWorkspace "C:\\Jenkins\\workspace"
}
}
environment {
def destination=''
}
options {
timestamps()
timeout(time: 60, unit: 'MINUTES')
skipDefaultCheckout(true)
disableConcurrentBuilds()
}
stages {
stage('TEST')
{
steps {
script{
destination="\\\\SERVERNAME\\d\$"
}
echo "${destination}"
powershell '''
$destinationPath ="${destination}"
write-host $destinationPath
write-host "test3" '''
}
}
}
post {
always {
deleteDir()
}
}
您可以使用以下两种方法之一来解决此问题,选择最适合您的方法:
使用“””代替“”即可替换destination
以其价值。使用此方法时,您应该转义 Powershell 的变量标识符以避免不需要的替换,如下所示:\$destinationPath = "${destination}"
将 Jenkins 变量导出为环境变量:
withEnv(["DESTINATION=$destination"]) {
powershell '''
$destinationPath ="$env:DESTINATION"
...
'''
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)