Home > Net >  Curl command in Github action fails on "no such file or directory"
Curl command in Github action fails on "no such file or directory"

Time:12-15

I am running my Github Action on a self-hosted machine. The action should send a curl command:

name: Build and Publish

on:
  push:
    branches:
      - master

jobs:
  trigger:
    runs-on: self-hosted
    steps:
      - uses: actions/checkout@v2
      - name: curl command
        working-directory: /home/ubuntu/actions-runner/_work/${{ github.repository }}
        run: |
          DATA= '{"data": { "repository" : "${{ github.repository }}", "package_version" : "0.1.0-${{ github.sha }}", "branch" : "${{ github.sha }}" }}'
          printf -v content "$DATA"
          curl --request 'POST' --data "$content" 'http://<my-url>/actions'

The output seems strange as it is looking for a certain path with an .sh script and fails on "no such file or directory"

    Run DATA= '{"data": { "repository" : "iz/<my-repo>", "package_version" : "0.1.0-41b1005d15069bbb515b52416721b84", "branch" : "41b1005d15069bbb515b52416721b84" }}'
  DATA= '{"data": { "repository" : "iz/<my-repo>", "package_version" : "0.1.0-41b1005d15069bbb515b52416721b84", "branch" : "41b1005d15069bbb515b52416721b84" }}'
  printf -v content "$DATA"
  curl --request 'POST' --data "$content" 'http://<my-url>/actions'
 
shell: /usr/bin/bash -e {0}
/home/ubuntu/actions-runner/_work/_temp/5fee3c-a409-4db-48f-cb1d16d15d.sh: line 1: {"data": { "repository" : "iz/<my-repo>", "package_version" : "0.1.0-41b1005d15069bbb515b52416721b84", "branch" : "41b1005d15069bbb515b52416721b84" }}:
No such file or directory
Error: Process completed with exit code 127.

CodePudding user response:

Try removing the space after DATA=. It thinks you are temporarily setting DATA to empty for executing the command '{"data": { "repository" :... instead of setting DATA to that value permanently (i.e. non-temporarily).

Set X to Y (until overwritten):

X=Y

Set X to Y temporarily during execution of CMD:

X=Y CMD
  • Related