Jenkins变量范围更改

Jenkins变量范围更改,jenkins,devops,Jenkins,Devops,有人能告诉我如何在Jenkins作业中更改变量的范围吗?目前我正在通过ssh在远程系统上执行bash脚本。bash脚本生成一个密码,我需要将该密码传递给Jenkins作业中的电子邮件通知配置。当变量传递给电子邮件通知配置时,该密码为空。 欢迎提供修复建议。我建议使用脚本化管道作业,如下所示: node('label') { // You would need to make sure only thing printed to stdout is the password def pas

有人能告诉我如何在Jenkins作业中更改变量的范围吗?目前我正在通过ssh在远程系统上执行bash脚本。bash脚本生成一个密码,我需要将该密码传递给Jenkins作业中的电子邮件通知配置。当变量传递给电子邮件通知配置时,该密码为空。
欢迎提供修复建议。

我建议使用脚本化管道作业,如下所示:

node('label') {
  // You would need to make sure only thing printed to stdout is the password
  def password = sh(script: 'ssh ...', returnStdout:true).trim()

  // You can set it in the global environment like this:
  env.Password = password

  // Or use it directly
}

另一个选项是将密码写入代理工作区中的文件,然后使用
readFile()
从文件中读取密码。以下是的语法。

我建议使用脚本化管道作业,如下所示:

node('label') {
  // You would need to make sure only thing printed to stdout is the password
  def password = sh(script: 'ssh ...', returnStdout:true).trim()

  // You can set it in the global environment like this:
  env.Password = password

  // Or use it directly
}

另一个选项是将密码写入代理工作区中的文件,然后使用
readFile()
从文件中读取密码。以下是的语法。

您使用的是自由样式、管道脚本还是脚本化管道?@JRichardsz是自由样式作业?您使用的是自由样式、管道脚本还是脚本化管道?@JRichardsz是自由样式作业