pwsh environment variables aren't propagated

charlton's Avatar


31 Mar, 2022 12:16 AM

for example in the following token is passed to deploy but release_title is not

  - pwsh: $env:release_title="iricdev $(get-date -AsUTC -Format o)"
  - ps: $env:token=$env:scharlton2_access_token

  - provider: GitHub
    tag: LATEST
    release: $(release_title)
    description: 'Test release'
    auth_token: $(token)
  1. Support Staff 1 Posted by Feodor Fitsner on 03 Apr, 2022 04:15 AM

    Feodor Fitsner's Avatar

    That's because pwsh 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.

  2. 2 Posted by charlton on 03 Apr, 2022 08:06 PM

    charlton's Avatar

    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):
    Is there an easier way?

      - 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


  3. Support Staff 3 Posted by Feodor Fitsner on 03 Apr, 2022 11:41 PM

    Feodor Fitsner's Avatar
  4. 4 Posted by charlton on 04 Apr, 2022 03:26 PM

    charlton's Avatar

    Sorry, my question was is there a way to do it without the 'if ($true) {'.

    When I tried the following it didn't like the square bracket as the first character.

    - pwsh: [System.Environment]::SetEnvironmentVariable('release_title', "iricdev $(get-date -AsUTC -Format o)", 'Machine') }

    and I tried to escape using backslashes:

    - pwsh: \[System.Environment\]::SetEnvironmentVariable...
    - pwsh: \\[System.Environment\\]::SetEnvironmentVariable...

    but neither worked.

    I just wondered if there was another way to escape it.


  5. Support Staff 5 Posted by Feodor Fitsner on 04 Apr, 2022 03:48 PM

    Feodor Fitsner's Avatar

    Sure, I thought that condition was a placeholder for some logic :)

    Try this one please:

  6. 6 Posted by charlton on 04 Apr, 2022 10:53 PM

    charlton's Avatar


  7. charlton closed this discussion on 04 Apr, 2022 10:53 PM.

Comments are currently closed for this discussion. You can start a new one.

Keyboard shortcuts


? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac

Recent Discussions

13 Apr, 2024 04:43 PM
12 Apr, 2024 04:56 PM
11 Apr, 2024 11:16 PM
09 Apr, 2024 10:59 PM
08 Apr, 2024 07:50 AM


06 Apr, 2024 04:06 AM
05 Apr, 2024 01:26 PM
05 Apr, 2024 10:39 AM
04 Apr, 2024 03:41 PM
31 Mar, 2024 05:51 PM
30 Mar, 2024 01:59 PM