tag:help.appveyor.com,2012-11-13:/discussions/problems/31760-pwsh-environment-variables-arent-propagatedAppVeyor: Discussion 2022-04-04T22:53:20Ztag:help.appveyor.com,2012-11-13:Comment/527361122022-04-03T04:15:08Z2022-04-03T04:15:08Zpwsh environment variables aren't propagated<div><p>That's because <code>pwsh</code> scripts in Windows builds run in a separate process. However, in pwsh script you can put environment variables to a machine level and then in the following ps script read it from there and set to a local env variable.</p></div>Feodor Fitsnertag:help.appveyor.com,2012-11-13:Comment/527361122022-04-03T20:06:02Z2022-04-03T20:06:02Zpwsh environment variables aren't propagated<div><p>Okay, I didn't know about the different scopes of environment variables. I tried to escape the square brackets, but I couldn't get it to work. I had to resort to this (for the pwsh line):<br>
Is there an easier way?</p>
<pre>
<code>before_deploy:
- pwsh: if ($true) { [System.Environment]::SetEnvironmentVariable('release_title', "iricdev $(get-date -AsUTC -Format o)", 'Machine') }
- ps: $env:release_title=[System.Environment]::GetEnvironmentVariable('release_title', 'Machine')
- ps: $env:token=$env:scharlton2_access_token</code>
</pre>
<p>Thanks</p></div>charltontag:help.appveyor.com,2012-11-13:Comment/527361122022-04-03T23:41:02Z2022-04-03T23:41:02Zpwsh environment variables aren't propagated<div><p>I've got it working: <a href="https://gist.github.com/FeodorFitsner/bad29768ea24f8bdaae28677ba49fdfc">https://gist.github.com/FeodorFitsner/bad29768ea24f8bdaae28677ba49fdfc</a></p>
<p>Test build: <a href="https://ci.appveyor.com/project/FeodorFitsner/simple-console/builds/43116446">https://ci.appveyor.com/project/FeodorFitsner/simple-console/builds...</a></p></div>Feodor Fitsnertag:help.appveyor.com,2012-11-13:Comment/527361122022-04-04T15:26:20Z2022-04-04T15:26:20Zpwsh environment variables aren't propagated<div><p>Sorry, my question was is there a way to do it without the 'if ($true) {'.</p>
<p>When I tried the following it didn't like the square bracket as the first character.</p>
<pre>
<code>- pwsh: [System.Environment]::SetEnvironmentVariable('release_title', "iricdev $(get-date -AsUTC -Format o)", 'Machine') }</code>
</pre>
<p>and I tried to escape using backslashes:</p>
<pre>
<code>- pwsh: \[System.Environment\]::SetEnvironmentVariable...</code>
</pre>
<pre>
<code>- pwsh: \\[System.Environment\\]::SetEnvironmentVariable...</code>
</pre>
<p>but neither worked.</p>
<p>I just wondered if there was another way to escape it.</p>
<p>Thanks</p></div>charltontag:help.appveyor.com,2012-11-13:Comment/527361122022-04-04T15:48:56Z2022-04-04T15:48:56Zpwsh environment variables aren't propagated<div><p>Sure, I thought that condition was a placeholder for some logic :)</p>
<p>Try this one please: <a href="https://gist.githubusercontent.com/FeodorFitsner/bad29768ea24f8bdaae28677ba49fdfc/raw/3f9075b52e55d1f1fb30823b7aca50cee0d66a4d/gistfile1.txt">https://gist.githubusercontent.com/FeodorFitsner/bad29768ea24f8bdaa...</a></p></div>Feodor Fitsnertag:help.appveyor.com,2012-11-13:Comment/527361122022-04-04T22:53:00Z2022-04-04T22:53:00Zpwsh environment variables aren't propagated<div><p>Thanks</p></div>charlton