pwsh environment variables aren't propagated

charlton's Avatar

charlton

31 Mar, 2022 12:16 AM

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

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

deploy:
  - 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?

    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
    

    Thanks

  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.

    Thanks

  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: https://gist.githubusercontent.com/FeodorFitsner/bad29768ea24f8bdaa...

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

    charlton's Avatar

    Thanks

  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

Generic

? 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