Error with set-env on self hosted runner ==> [error]No such file or directory

While testing use of “set-env” on a self-hosted runner (2.164.0), I get “No such file or directory” error.  

Run echo ::set-env name=ENVIRONMENT::staging
echo ::set-env name=ENVIRONMENT::staging
shell: /usr/bin/bash -e {0}
##[error]No such file or directory

I’ve tried a few variations, but all the same result. I’m not able to get any of the commands mentioned on this page to work.  Anyone else running into these problems? I see a couple of new versions of the runner, but not officially released yet.

Is your repository public?  If so, can you point me to the workflow?  If not, can you copy and paste your workflow file?

1 Like

Not a public repo, but this is relevant and obfuscated workflow file. The clean workspace step works fine, but the “set-env” step fails every time with error, “[error]No such file or directory”

name: Build and Deploy ProjectX

on:
  push:
    branches:
      - master
      - xxxxxx
      - xxxxxx
jobs:
  ProjectX_build_job:
    runs-on: self-hosted
    name: Build ProjectX
    steps:
      - name: Clean Workspace
        run: sudo rm -rf $GITHUB_WORKSPACE
      - name: Setup for MASTER branch
        if: endsWith(github.ref, 'master')
        run: |
          echo ::set-env name=ENVIRONMENT::staging
          echo ::set-env name=SLACKWEBHOOK::${{ secrets.STAGING_SLACK_WEBHOOK_URL }}
...

I replied, but the response got marked as spam and removed?

Trying to upload snippet of workflow YAML one more time…

name: Build and Deploy ProjectX

on:
  push:
    branches:
      - master
      - xxxx
      - yyyy

jobs:

  projectx_build_job:
    runs-on: self-hosted
    name: Build ProjectX
    steps:
      - name: Clean workspace
        run: sudo rm -rf $GITHUB_WORKSPACE

      - name: Setup for MASTER branch
        if: endsWith(github.ref, 'master')
        run: |
          echo ::set-env name=ENVIRONMENT::staging
          echo ::set-env name=SLACKWEBHOOK::${{ secrets.STAGING_SLACK_WEBHOOK_URL }}
...

This looks like an issue with your self-hosted runner - in particular, it looks like you can’t find the echo command.  This seems like it may be a problem with your PATH?  What if you try /bin/echo instead of echo?

I suspected something like that at first, but echo and /bin/echo appear to work.  I’ve tested from an action and also when SSH session.  Both are running as default ec2-user.  

After turning on debugging for steps/runners (see enabling debug logging) I’m seeing more details.  Doing more digging into those details.

From debug output, the first command with echo works just fine:

2020-02-05T17:10:57.0357003Z ##[group]Run sudo rm -rf $GITHUB_WORKSPACE
2020-02-05T17:10:57.0357730Z [36;1msudo rm -rf $GITHUB_WORKSPACE[0m
2020-02-05T17:10:57.0369379Z shell: /usr/bin/bash -e {0}
2020-02-05T17:10:57.0369945Z ##[endgroup]
2020-02-05T17:10:57.0387553Z ##[debug]/usr/bin/bash -e /mnt2/actions-runner/_work/_temp/af6bc143-becf-460a-8d01-bf7909199eb3.sh
2020-02-05T17:10:57.0639965Z ##[debug]Finishing: Clean workspace

But the command with the set-env fails.

2020-02-05T17:10:57.0745992Z ##[group]Run echo ::set-env name=action_state::yellow
2020-02-05T17:10:57.0746488Z [36;1mecho ::set-env name=action_state::yellow[0m
2020-02-05T17:10:57.0753669Z shell: /usr/bin/bash -e {0}
2020-02-05T17:10:57.0754045Z ##[endgroup]
2020-02-05T17:10:57.0764310Z ##[debug]/usr/bin/bash -e /mnt2/actions-runner/_work/_temp/49b66d49-13f9-47b3-8283-9870cf2dc0f0.sh
2020-02-05T17:10:57.0795015Z ##[error]No such file or directory

Is there any way to preserve the temp .sh files.  Real curious to see inside these.  They get cleaned up after build finishes.

I copied the files before they were cleaned up.  Nothing more than the actual commands.

I’ve found the answer after more testing.  Looks like something fishy with this step that was running before echo because when I remove that cleanup step, all the echo commands work fine.  Going to call this resolved and dig into why cleanup is messing things up. Bizarre.

      - name: Clean Workspace
        run: sudo rm -rf $GITHUB_WORKSPACE
1 Like

After more testing, here are my findings.

  1. Self-hosted runners don’t start with clean workspace (see documentation), so step to cleanup had been added

  2. Any shell commands (e.g. echo set-env) that happen AFTER cleanup (sudo rm -rf $GITHUB_WORKSPACE) will fail with “No such file or directory”

  3. If add checkout step before any shell commands, the echo set-env will work as expected.  There must be some additional context (setting path) that gets clobbered with rm command.

2 Likes

thanks rboekweg for the solution that it is very strange that we need checkout code first (add actions/checkout@v2) to make setup env work…
this waste me a day to test why cannot set env variable as i comment out all checkout code just try set variable syntax