[英]variable set in Windows Powershell of Jenkins build, not available in other build steps
I have a Jenkins build with one parameter called VERSION.我有一个带有一个名为 VERSION 的参数的 Jenkins 版本。
Based on the length of the variable i am modifying its value in Windows Powershell and then in the next build step, i want to use it.根据变量的长度,我在 Windows Powershell 中修改它的值,然后在下一个构建步骤中,我想使用它。
But the modified value is not being reflected in the next build step execution, it still refer to the intial value entered as a parameter.但是修改后的值并没有反映在下一个构建步骤执行中,它仍然引用作为参数输入的初始值。 I tried ENV,script,global none of them seems to work.我试过 ENV,script,global 它们似乎都不起作用。
Windows powershell build step Windows PowerShell 构建步骤
input VERSION=1810(via jenkins build)输入 VERSION=1810(通过 jenkins 构建)
if ("$ENV:VERSION".length -eq 4)
{
$ENV:VERSION = "$ENV:VERSION",3 -join "" (here it will be 18103)
}
Write-Output "$ENV:VERSION" (18103 here aswell)
This is a general issue with environment variable scope.这是环境变量作用域的普遍问题。 Every process inherits the environment variables from its parent, but has its own copy, and any modifications you make will only be reflected in the current process and child processes.每个进程都从其父进程继承环境变量,但有自己的副本,您所做的任何修改只会反映在当前进程和子进程中。
I think you will have to find some way to pass the value to a future step that doesn't rely on environment variables.我认为您必须找到某种方法将值传递给不依赖于环境变量的未来步骤。
You can try to use EnvInject Plugin and set additional PROJ_VERSION=$ENV:VERSION
variable in your job.您可以尝试使用EnvInject 插件并在您的工作中设置额外的PROJ_VERSION=$ENV:VERSION
变量。 In this case it should be working correctly.在这种情况下,它应该可以正常工作。 If it isn't working within Properties Content
directly, try to use injection via file as in this example.如果它不能直接在Properties Content
工作,请尝试像本例中那样通过文件使用注入。
I found another option which works in Freestyle project jobs.我发现了另一种适用于 Freestyle 项目工作的选项。
the 1st powershell step:第一个 powershell 步骤:
[Environment]::SetEnvironmentVariable('IMAGE_VERSION', $imageVersion, 'Machine')
the 2nd powershell step:第二个powershell步骤:
$imageVersion = [Environment]::GetEnvironmentVariable('IMAGE_VERSION', 'Machine')
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.