4

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.

8
  • Does it run by specifying its full path i.e. testfolder/testbatch.bat? Commented Mar 26, 2023 at 9:12
  • Looks like you have already created an issue on that image repo (github.com/philips-labs/terraform-aws-github-runner/issues/3095). Commented Mar 26, 2023 at 9:18
  • What version of the runner are you using? Does it support the new syntax? Have you tried the old ::add-path syntax? Commented Mar 26, 2023 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. Commented Mar 26, 2023 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. Commented Mar 26, 2023 at 11:03

2 Answers 2

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.

Sign up to request clarification or add additional context in comments.

Comments

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.

6 Comments

Thats awesome. How did you build the image? Can you share source for your packer project may be?
I just installed the runner manually.
The most recent images for the hosted runner are now here: github.com/actions/runner-images/tree/main/images%2Fwin
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.
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.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.