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

时间:2017-09-28 15:48:06

标签: powershell jenkins groovy 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"
      '''
  }
  }

1 个答案:

答案 0 :(得分:5)

您无法在单引号或三重单引号中插入变量。使用三重双引号:

  stdoutpowershell = powershell returnStdout: true, script: """
      write-output "Server is $envserverName"
  """