Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

variable set in Windows Powershell of Jenkins build, not available in other build steps

I have a Jenkins build with one parameter called VERSION.

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.

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.

Windows powershell build step

input VERSION=1810(via jenkins build)

           if ("$ENV:VERSION".length -eq 4)
        {
           $ENV:VERSION = "$ENV:VERSION",3 -join ""  (here it will be 18103)
         }

         Write-Output "$ENV:VERSION" (18103 here aswell)

later in the Nexus artifact uploader i refer to this variable as ${VERSION} and the above updated value is not being reflected

                 (here it is 1810 and not 18103) 

Please help

like image 423
wehelpdox Avatar asked Oct 22 '25 17:10

wehelpdox


1 Answers

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.

like image 171
briantist Avatar answered Oct 25 '25 10:10

briantist



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!