0

I am trying to update a local server running some non-production versions of some of my company's sites to update whenever the main repository merges a pull request. However, the action stalls out when the action hits the git pul ... line. The logs do not provide any information, the process seemingly halts. I can run the same commands in the command prompt. Any advice is appreciated.

main.yml

name: CI
    
    on:
       
      push:
        branches: [ master ]
    
       
      workflow_dispatch:
    
     
    jobs:
       
      deployment:
         
        runs-on: self-hosted
    
         
        steps:
           
          - uses: actions/checkout@v2
    
           
          - name: Test
            shell: cmd
            run: actions.cmd

actions.cmd

cd path\to\stuff
git pull remoteName master

Update, ran into some weird caching issues but was able to clean up a little and got some error messages:

nothing to commit, working tree clean
fatal: 'github' does not appear to be a git repository
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.
success
Error: Process completed with exit code 1.

github is the name of the remote. Again, I can run these scripts normally, but maybe the workflow needs some additional authentication?

  • As far as I know, when you use `actions/checkout@v2`, you don't have to pull from the remote repo. – Orian Zinger Mar 02 '22 at 20:39
  • Remember that pull = fetch + 2nd-command-of-your-choice. In scripts, avoid pull in favor of the more verbose two-command sequence, so as to have full control and improved debug-ability. In this case it's the fetch step failing: the clone that GitHub are using to run this action has no remote named `github`. Presumably you need a `git remote add` step here, although the clone that GitHub are using is *from* the GitHub clone in the first place, so that seems a little odd. – torek Mar 02 '22 at 22:03
  • If you *don't* need the fetch step (and you won't if you make a full clone; remember that `checkout@v2` makes a shallow, single-branch clone by default), you can just run the *second* step command directly. That's likely to be the way to go. – torek Mar 02 '22 at 22:05

2 Answers2

2

To pay it forward and potentially save someone else some grief, I'll shed a little more light on this. I faced a similar issue. I wanted to run a git pull command on a self-hosted runner.

To execute the pull command on the runner, you need to provide authentication in your command. You can use a Personal Access Token to authenticate. With token authentication, the command looks like: git pull https://<token>@github.com/<repo_url.git>

I wrapped up the whole command in a secret I named PULL.

My final workflow looks like this:

name: CI

on:
  push:
    branches: [ master ]

jobs:
  deployment:
    runs-on: self-hosted
    steps:
    - name: Test
      working-directory: <path to repo>
      shell: cmd
      run: ${{ secrets.PULL }}
Noah
  • 21
  • 2
0

Turns out it was an authentication issue. Unfortunately, debugging when actions are being executed on the runner (even when self-hosted) is very frustrating. If anyone knows a better way please feel free to update me.

Basically the runner did not have the same access rights as the server that was hosting the runner, so I just had to add some authentication steps to the scripts. I thought it would since I already configured the server to successfully run the same commands manually, but this does seem like a good security measure.