AlexS
AlexS

Reputation: 927

Cannot update GITHUB_PATH on self-hosted windows github action-runner

I have following workflow

name: Test set path
on:
  workflow_dispatch:
jobs:
  test-cross-aws:
    runs-on: [self-hosted, '${{ matrix.platform.os }}', x64, '${{ matrix.platform.label }}']
    #runs-on: windows-latest   
    strategy:
      matrix:
        platform: [{ os: windows, label: wix-aws-windows-test }]
    steps:
      - name: create fake batchfile
        if: always()
        run: |
           mkdir testfolder
           echo "@echo off" | Out-File -FilePath testfolder/testbatch.bat -Encoding utf8
           echo "echo SOMETHING" | Out-File -FilePath testfolder/testbatch.bat -Encoding utf8           

      - name: add path
        if: always()
        run: echo "$pwd\testfolder;" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append

      - name: run custom binary with path
        if: always()
        run: testbatch.bat

It works ok on regular github action windows runner. But it fails on self-hosted github runner built from this image The error is

testbatch.bat : The term 'testbatch.bat' is not recognized as the name of a cmdlet, function, script file, or operable 
program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At C:\actions-runner\_work\_temp\744d9b45-8f99-4db5-ba7d-b95aad4dde97.ps1:2 char:1
+ testbatch.bat
+ ~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (testbatch.bat:String) [], ParentContainsErrorRecordException
    + FullyQualifiedErrorId : CommandNotFoundException
 
Error: Process completed with exit code 1.

Github runner version is 2.303.0 Windows i use is Windows 2022 datacenter.

Upvotes: 4

Views: 1402

Answers (2)

Hanan
Hanan

Reputation: 1

a possible solution is to reinstall the self-hosted runner as a user and make sure this user has the specific permissions you need. the default mode for self-hosted runners when you run the script is to be installed as a network service which might not have all permissions. you can check this by running whoami from your action to make sure.

Upvotes: 0

jessehouwing
jessehouwing

Reputation: 114967

I suspect you're running an outdated version of the GitHub Runner that doesn't support the new syntax to add variables to the path.

If you are using self-hosted runners make sure they are updated to version 2.273.1 or greater.

I just ran this workflow (slightly simplified further) without failure on a self-hosted agent on Windows 11 Pro:

name: Test set path
on:
  workflow_dispatch:
  
jobs:
  test:
    runs-on: [self-hosted]

    steps:
      - run: |
           mkdir testfolder -force | out-null
           echo "@echo off" > testfolder/testbatch.bat
           echo "echo SOMETHING" >> testfolder/testbatch.bat
      - run: |
            "$pwd\testfolder" >> $env:GITHUB_PATH
      - run: |
            & testbatch.bat

Which succeeded without any problems:

enter image description here

To check the contents of the $env:GITHUB_PATH simply write its content to the console:

gc $env:GITHUB_PATH | write-output

The magic GITHUB_ environment variables point to a temporary file which is read by the runner after the step has finished. The environment variable provides us a way from knowing the name of the file without having to know the name of the file.

Upvotes: 0

Related Questions