5

Building docker image....... /usr/bin/env: ‘sh\r’: No such file or directory execution failed

complete script

#!/bin/bash
 echo "Building docker image......."
. gradle.properties
 IMAGE="$dockerRegistry/$1"
 IMAGE_TAG="$releaseVersion-$(git log -1 --pretty=%h)"
 if ./gradlew clean :$1:jibDockerBuild -x test; then
 echo "Pushing docker image...."
 docker tag $IMAGE $IMAGE:$IMAGE_TAG
 docker push $IMAGE:$IMAGE_TAG
 else
 echo "execution failed"
 exit 1
  fi
 exit 0
  • Can you also post your Dockerfile here? – Nguyen Lam Phuc Apr 03 '20 at 01:48
  • 2
    `$'\r'` is the carriage return. Your code is presumably saved as a DOS/Windows text file, not a UNIX one. DOS text files separate lines with a `CRLF` sequence (`$'\r\n'`), whereas UNIX text files *end* lines (including the last one) with a linefeed alone (`$'\n'`). – Charles Duffy Apr 03 '20 at 01:59
  • 1
    See the very first entry in the "Before asking about problematic code" section of https://stackoverflow.com/tags/bash/info – Charles Duffy Apr 03 '20 at 02:00
  • Does this answer your question? [Are shell scripts sensitive to encoding and line endings?](https://stackoverflow.com/questions/39527571/are-shell-scripts-sensitive-to-encoding-and-line-endings) – Charles Duffy Apr 03 '20 at 02:01
  • 2
    That said, it's a different program that's throwing your error, not this one. This code isn't using `env` *or* `sh`. Maybe it's your copy of `gradlew` that's checked in that way? Either way, whichever program it is, the bug is as described above. – Charles Duffy Apr 03 '20 at 02:01
  • 1
    Add printing commands at the top of your script `set -x` to narrow down which command exactly fails your script. – makozaki Apr 03 '20 at 08:29

1 Answers1

8

Try to adjust your file endings for gradlew file:

   dos2unix .\gradlew
Altay Hunoğlu
  • 113
  • 3
  • 8