将变量传递给jenkins管道中的powershell脚本块 [英] Passing variables to powershell script block in a jenkins pipeline

查看:329
本文介绍了将变量传递给jenkins管道中的powershell脚本块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法在Powershell脚本中使用Groovy变量?我的示例脚本如下.

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"
      '''
  }
  }

推荐答案

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

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"
  """

这篇关于将变量传递给jenkins管道中的powershell脚本块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆