简体   繁体   中英

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

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.

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 (ie non-temporarily).

Set X to Y (until overwritten):

X=Y

Set X to Y temporarily during execution of CMD:

X=Y CMD

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM