3

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.

AlexS
  • 927
  • 4
  • 16
  • 29
  • Does it run by specifying its full path i.e. `testfolder/testbatch.bat`? – Azeem Mar 26 '23 at 09:12
  • Looks like you have already created an issue on that image repo (https://github.com/philips-labs/terraform-aws-github-runner/issues/3095). – Azeem Mar 26 '23 at 09:18
  • What version of the runner are you using? Does it support the new syntax? Have you tried the old `::add-path` syntax? – jessehouwing Mar 26 '23 at 10:16
  • Try changing `echo $pwd/path" |` to simply `"$pwd/path;" |`, no need to echo here when simply piping a string to the file. Also, it looks like the script should be using PowerShell core, in which case you can use the simplified notation: `"$pwd/file" >> $env:GITHUB_PATH`. – jessehouwing Mar 26 '23 at 10:21
  • Thanks for replies. 1. Github runner version is 2.303.0. 2. Yes ive tried old version with add-path, not working. 3. Ive tried various combinations of sytax, nothing worked so far. I guess its something with how instance starts the github agent. – AlexS Mar 26 '23 at 11:03
  • In your script you have a `;` after your path, that's not what you want. Did you try my workflow below verbatim? – jessehouwing Mar 26 '23 at 12:37
  • Have you configured the debug variables and extracted the runner logs from the agent to see whether there are any read/write issues? – jessehouwing Mar 26 '23 at 15:40
  • yes. There are no read/write issues. Ive started local instance of windows 2022 server on my computer. It executes this workflow without error. – AlexS Mar 28 '23 at 18:34

2 Answers2

0

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.

jessehouwing
  • 106,458
  • 22
  • 256
  • 341
  • Thats awesome. How did you build the image? Can you share source for your packer project may be? – AlexS Mar 26 '23 at 10:59
  • I just installed the runner manually. – jessehouwing Mar 26 '23 at 11:00
  • The most recent images for the hosted runner are now here: https://github.com/actions/runner-images/tree/main/images%2Fwin – jessehouwing Mar 26 '23 at 11:02
  • Thats no fun:) manually yes everything runs, i suppose because it runs under your username as regular app. It breaks down when it started automatically in aws. – AlexS Mar 26 '23 at 11:05
  • Try running my above workflow and see if it works. ☝️ There is no reason running it as a service shouldn't work here. But that information is an important addition. Try writing `$env:PATH` to the console to see if there is any funny business in the path. – jessehouwing Mar 26 '23 at 11:11
  • I reconfigured my runner to run as a service and that didn't make any difference. – jessehouwing Mar 26 '23 at 11:21
0

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.

Hanan
  • 1
  • 1
  • 1