将变量传递给jenkins管道中的powershell脚本块

can*_*maz 3 powershell groovy jenkins jenkins-pipeline

有没有办法在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"
      '''
  }
  }
Run Code Online (Sandbox Code Playgroud)

Rob*_*les 6

您不能在单引号或三单引号中插入变量.使用三双引号:

  stdoutpowershell = powershell returnStdout: true, script: """
      write-output "Server is $envserverName"
  """
Run Code Online (Sandbox Code Playgroud)