Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fixing PowerShell in the Yaml Pipeline

I have an existing Yaml pipeline which I am trying to understand and fix certain things. Since I am new to this, there are few things I am unable to understand in this existing pipeline. I would like to know what below task is doing. I don't see any inline PowerShell script here, then why it is created as PowerShell. The task is to add POMLXX dll in ABC_x64-$(osSuffix)\bin folder, but how the below script is even doing it

- powershell: |
            Set-Variable -Name PATH -Value "$env:PATH;$(IppRoot)\redist\intel64_win\ipp;$(Build.SourcesDirectory)\ABC_x64-$(osSuffix)\bin;$(Build.BinariesDirectory);$(PuLib)/imports/Pulib67/dll/amd64;$(POMLXX)/runtimes/win-x64/native"
            Write-Host "##vso[task.setvariable variable=PATH]$PATH"
          displayName:  'Add AbcRoot, IPP binaries, Pulib67 and POMLXX to PATH on Win'
          condition:    eq(variables['Agent.OS'], 'Windows_NT')

- bash: |
            export LD_LIBRARY_PATH="$(IppRoot)/redist/intel64_win/ipp:$(Build.SourcesDirectory)/MyProject_x64-$(osSuffix)/lib"
            echo "##vso[task.setvariable variable=LD_LIBRARY_PATH]$LD_LIBRARY_PATH"
            echo "##vso[task.setvariable variable=DYLD_LIBRARY_PATH]$LD_LIBRARY_PATH"
          displayName:  'Add OrzRoot, IPP binaries and LibFT4222 to (DY)LD_LIBRARY_PATH on Linux and Mac'
          condition:    in(variables['Agent.OS'], 'Darwin', 'Linux')
like image 314
ZZZSharePoint Avatar asked Nov 30 '25 20:11

ZZZSharePoint


1 Answers

This piece is the powershell:

Set-Variable -Name PATH -Value "$env:PATH;$(IppRoot)\redist\intel64_win\ipp;$(Build.SourcesDirectory)\ABC_x64-$(osSuffix)\bin;$(Build.BinariesDirectory);$(PuLib)/imports/Pulib67/dll/amd64;$(POMLXX)/runtimes/win-x64/native"
Write-Host "##vso[task.setvariable variable=PATH]$PATH"

It adds a bunch of paths to the PATH powershell variable (set-variable -Name PATH) including the path environment variable that came down from the agent, and then exports that back to the agent (Write-Host with a special command string) by re-setting the Azure Pipelines PATH variable. That variable will be set in the context of subsequent tasks so that they can find the tools.

It is a bit of a hack to preserve changes to the environment to a new task in the same job context.

See also:

  • Logging commands

The | after powershell: instructs the YAML parser to interpret the next indented block as a multi-line string.

See also:

  • YAML - Multiline Strings - literal styles with pipe operator

A better solution

There is a better solution, it looks pretty similar:

powershell: |
  write-host "##vso[task.prependpath]$(IppRoot)\redist\intel64_win\ipp"
  write-host "##vso[task.prependpath]$(Build.SourcesDirectory)\ABC_x64-$(osSuffix)\bin"
  ... etc

This command is specifically created to add paths to the PATH environment and will work even if other Tool Installer tasks run after your script section.

See also:

  • Logging commands - PrependPath: Prepend a path to the PATH environment variable
like image 64
jessehouwing Avatar answered Dec 03 '25 15:12

jessehouwing



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!