如何使用Jenkinsfile将Powershell变量从一个会话传递到另一个会话或从一个阶段传递到另一个阶段

编程入门 行业动态 更新时间:2024-10-27 00:26:22
本文介绍了如何使用Jenkinsfile将Powershell变量从一个会话传递到另一个会话或从一个阶段传递到另一个阶段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

每次关闭powershell会话或窗口时,在其中创建的所有变量都会被破坏.是否有任何命令或方法来创建即使关闭会话也不会破坏的变量. 我知道使用脚本可以工作,但是我的情况是我的jenkins阶段打开一个窗口并创建一个变量,然后关闭该阶段以关闭会话,在下一阶段将打开新的会话,但所有初始变量都会丢失.我尝试使用jenkins环境变量,但即使它在powershell脚本中已更新,但在下一个会话中它又再次获得了相同的变量.

Every time I close the powershell session or window all the variable created in there is destroyed. Is there any command or way to create a variable which does not gets destoryed evenafter the session is closed. I know using script works but my situation is that my jenkins stage opens one window and creates a variable and the stage is closed which closes the session and in the next stage the new session is opened but all the initial variables are lost. I tried using jenkins environment variable but even though it is updated inside the powershell script but in next session it again gets same variable back.

推荐答案

作为会话1的示例,我们将变量设置为1.

As an example Session 1 our variable is set to a value of 1.

$a = 1 $a | export-clixml -path c:\temp\a.xml

现在关闭会话,然后在重新启动Powershell或新启动的会话后运行此代码.

now close the session then run this code after you relaunch Powershell or a newly started session.

if(test-path c:\temp\a.xml) { $a = import-clixml -Path c:\temp\a.xml } $a 1

更多推荐

如何使用Jenkinsfile将Powershell变量从一个会话传递到另一个会话或从一个阶段传递到另一个阶段

本文发布于:2023-07-25 12:11:34,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1209766.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:阶段   如何使用   变量   Powershell   Jenkinsfile

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!