有没有办法在Powershell脚本中使用Groovy变量?我的示例脚本如下。
node { stage('Invoke Installation') { def stdoutpowershell def serverName = env.fqdn withEnv(['serverName = $serverName']) { echo "serverName : $serverName" stdoutpowershell = powershell returnStdout: true, script: ''' write-output "Server is $env:serverName" ''' } }
您不能在单引号或三单引号中插入变量。使用三重双引号:
stdoutpowershell = powershell returnStdout: true, script: """ write-output "Server is $envserverName" """