PowerShell comments changes the script

ahl's Avatar

ahl

15 Jul, 2022 08:37 AM

This works:

  - ps: >-
      $ErrorActionPreference = "Stop";

      ./versionize.ps1 | %{ Update-AppveyorBuild -Version $_ };

      $env:REPO_TAG_DESCRIPTION = (git tag -l --format='%(contents)' $env:APPVEYOR_REPO_TAG_NAME | Where-Object {$_}) -join "<br />";
      Write-Host $env:REPO_TAG_DESCRIPTION;

This does not:

  - ps: >-
      $ErrorActionPreference = "Stop";

      ./versionize.ps1 | %{ Update-AppveyorBuild -Version $_ };

      # Environment variables are truncated to the first line in appveyor (see https://github.com/appveyor/ci/issues/1688) 
      # so we join these together as html - and it finally works. We take the message from the tag and use as release message.
      $env:REPO_TAG_DESCRIPTION = (git tag -l --format='%(contents)' $env:APPVEYOR_REPO_TAG_NAME | Where-Object {$_}) -join "<br />";
      Write-Host $env:REPO_TAG_DESCRIPTION;

In the last script the environment variable is not set.

  1. Support Staff 1 Posted by Feodor Fitsner on 15 Jul, 2022 03:08 PM

    Feodor Fitsner's Avatar

    Yep, because ps: >- joins everything into a single line if there are no gaps between them. You should either put an empty line between last four lines:

      - ps: >-
          $ErrorActionPreference = "Stop";
    
          ./versionize.ps1 | %{ Update-AppveyorBuild -Version $_ };
    
          # Environment variables are truncated to the first line in appveyor (see https://github.com/appveyor/ci/issues/1688)
    
          # so we join these together as html - and it finally works. We take the message from the tag and use as release message.
    
          $env:REPO_TAG_DESCRIPTION = (git tag -l --format='%(contents)' $env:APPVEYOR_REPO_TAG_NAME | Where-Object {$_}) -join "<br />";
    
          Write-Host $env:REPO_TAG_DESCRIPTION;
    

    or use ps: | instead:

      - ps: |
          $ErrorActionPreference = "Stop";
          ./versionize.ps1 | %{ Update-AppveyorBuild -Version $_ };
          # Environment variables are truncated to the first line in appveyor (see https://github.com/appveyor/ci/issues/1688)
          # so we join these together as html - and it finally works. We take the message from the tag and use as release message.
          $env:REPO_TAG_DESCRIPTION = (git tag -l --format='%(contents)' $env:APPVEYOR_REPO_TAG_NAME | Where-Object {$_}) -join "<br />";
          Write-Host $env:REPO_TAG_DESCRIPTION;
    

    otherwise, with ps: >- the last block becomes:

    # Environment variables are truncated to the first line in appveyor (see https://github.com/appveyor/ci/issues/1688) # so we join these together as html - and it finally works. We take the message from the tag and use as release message. $env:REPO_TAG_DESCRIPTION = (git tag -l --format='%(contents)' $env:APPVEYOR_REPO_TAG_NAME | Where-Object {$_}) -join "<br />"; Write-Host $env:REPO_TAG_DESCRIPTION;
    

    basically a single comment.

    Let me know if you have any questions.

  2. Feodor Fitsner closed this discussion on 14 Sep, 2022 09:02 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