title: Jenkins "file not found" error with existing Bash script
body: <p>My goal is to have Jenkins 2 execute alpha integration tests between an express js app and a postgres db. I am to spin up containerized resources locally and test successfully with bash scripts that employ <code>docker-compose</code>. The relevant bash script is <code>scripts/docker/dockerRunTest.sh</code>.</p>
  
  <p>However, when I try to do the same thing via Jenkins, Jenkins claims that the initiating script is not found. </p>
  
  <p><strong>Jenkinsfile</strong></p>
  
  <pre><code>stage('Alpha Integration Tests') {
    agent {
      docker {
        image 'tmaier/docker-compose'
        args '-u root -v /var/run/docker.sock:/var/run/docker.sock --network host'
      }
    }
    steps {
      sh 'ls -lah ./scripts/docker/'
      sh './scripts/docker/dockerRunTest.sh'
    }
  }
  </code></pre>
  
  <p><strong>Output</strong></p>
  
  <pre><code>+ ls -lah ./scripts/docker/
  total 36
  drwxr-xr-x    2 root     root        4.0K Jan 26 21:31 .
  drwxr-xr-x    6 root     root        4.0K Jan 26 20:54 ..
  -rwxr-xr-x    1 root     root        2.2K Jan 26 21:31 docker.lib.sh
  -rwxr-xr-x    1 root     root         282 Jan 26 21:31 dockerBuildApp.sh
  -rwxr-xr-x    1 root     root         289 Jan 26 21:31 dockerBuildTestRunner.sh
  -rwxr-xr-x    1 root     root         322 Jan 26 21:31 dockerDown.sh
  -rw-r--r--    1 root     root         288 Jan 26 21:31 dockerRestart.sh
  -rwxr-xr-x    1 root     root         482 Jan 26 21:31 dockerRunTest.sh
  -rwxr-xr-x    1 root     root         284 Jan 26 21:31 dockerUp.sh
  
  + ./scripts/docker/dockerRunTest.sh
  /var/jenkins_home/workspace/project-name@2@tmp/durable-9ac0d23a/script.sh: line 1: ./scripts/docker/dockerRunTest.sh: not found
  ERROR: script returned exit code 127
  </code></pre>
  
  <p>The file clearly exists per the <code>ls</code> output. I have some hazy idea that there may be some conflict between how shell scripts and bash scripts work, but I cannot quite grasp the nuance in how Jenkins is not able to execute a script that clearly exists.</p>
  
  <p>edit (including script contents):<br>
  <strong>dockerRunTest.sh</strong></p>
  
  <pre><code>#!/bin/bash
  
  MY_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &amp;&amp; pwd -P )"
  MY_DIR="${MY_DIR:?}"
  SCRIPTS_DIR="$(realpath "${MY_DIR}/..")"
  ROOT_DIR="$(realpath "${SCRIPTS_DIR}/..")"
  TEST_DIR="${ROOT_DIR}/test/integration"
  SRC_DIR="${ROOT_DIR}/src"
  REPORTS_DIR="${ROOT_DIR}/reports"
  
  . "${SCRIPTS_DIR}/docker/docker.lib.sh"
  
  dockerComposeUp
  dockerExecuteTestRunner
  dockerComposeDown
  </code></pre>
  
  <p><strong>docker.lib.sh</strong></p>
  
  <pre><code>#!/bin/bash
  
  CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &amp;&amp; pwd -P )"
  CURRENT_DIR="${CURRENT_DIR:?}"
  SCRIPTS_DIR="$(realpath "${CURRENT_DIR}/..")"
  ROOT_DIR="$(realpath "${SCRIPTS_DIR}/..")"
  
  . "${SCRIPTS_DIR}/lib.sh"
  
  dockerComposeUp() {
    docker-compose build --no-cache
    docker-compose up --detach --force-recreate
    DC_CODE=$?
  
    if [ ${DC_CODE} -ne 0 ]; then
      # Introspection
      docker-compose logs
      docker-compose ps
  
      exit ${DC_CODE}
    fi
  }
  
  dockerComposeDown() {
    # docker-compose rm: Removes stopped service containers.
    #   -f, --force - Don't ask to confirm removal.
    #   -s, --stop - Stop the containers, if required, before removing.
    #   -v - Remove any anonymous volumes attached to containers.
    docker-compose rm --force --stop -v
  }
  
  dockerComposeRestart() {
    dockerComposeDown
    dockerComposeUp
  }
  
  dockerBuildTestRunner() {
    docker build -f test/Dockerfile -t kwhitejr/botw-test-runner .
  }
  
  dockerExecuteTestRunner() {
    IMAGE_NAME="kwhitejr/botw-test-runner"
  
    echo "Build new ${IMAGE_NAME} image..."
    dockerBuildTestRunner
  
    echo "Run ${IMAGE_NAME} executable test container..."
    docker run -it --rm --network container:api_of_the_wild_app_1 kwhitejr/botw-test-runner
  }
  </code></pre>