问题
Is there a way to use groovy variables inside a powershell script? My sample script is as following..
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"
'''
}
}
回答1:
You can't interpolate variables in single quotes or triple-single-quotes. Use triple-double-quotes:
stdoutpowershell = powershell returnStdout: true, script: """
write-output "Server is $envserverName"
"""
来源:https://stackoverflow.com/questions/46473385/passing-variables-to-powershell-script-block-in-a-jenkins-pipeline