简体   繁体   中英

Calling bash script inside AWS CodeBuild: script could not be found

I'm trying to run a small bash script inside my CodeBuild process as per the AWS documentation and this .

deploy.sh can be found in the src/ directory:

#!/bin/bash

pwd=$PWD

for dir in */ ; do
  target="$pwd/${dir%/}"
  cd "$target"
  npm install
  sls deploy && sls s3deploy
done

buildspec file:

version: 0.2

phases:
  install:
    runtime-versions:
      nodejs: 10
    commands:
    - cd backend/functions/src
    - npm install serverless
  build:
    commands:
    - ls
    - ./deploy.sh

after the ls command above in the logs, I can see that deploy.sh is there in the current directory.

Error:

/codebuild/output/tmp/script.sh: 4: /codebuild/output/tmp/script.sh: ./deploy.sh: not found

I've also tried using the command /bin/bash deploy.sh but this results in another error:

deploy.sh: line 2: $'\r': command not found

deploy.sh: line 4: $'\r': command not found

deploy.sh: line 7: $'\r': command not found

deploy.sh: line 8: syntax error near unexpected token `$'do\r''

deploy.sh: line 8: `for dir in */; do

The first answer by Walter A worked for me, this is what i did.

  1. Opened the file in VS Code
  2. At bottom left corner for Select End Of Line Sequence it showed CRLF 在此处输入图像描述
  3. clicked on CRLF and selected LF 在此处输入图像描述
  4. Uploaded the file to github and it started working.

(First written as a comment, it solved the problem)

The files were made in Windows.
Change CRLF to LF and the \\r is gone.

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