title: Jenkinsfile: permission denied when running sh step in Docker container
body: <p>I have trouble running a simple <code>Jenkinsfile</code> - e.g.</p>
  
  <pre><code>pipeline {
      agent { label 'ssh-slave' } 
      stages {
          stage('Shell Test') {
              steps {
                  sh 'echo "Hello World"'
              }
          }
      }
  }
  </code></pre>
  
  <p>The logfiles of Jenkins on the master show that the container was started successfully but the build job crashes with a message like</p>
  
  <pre><code>sh: 1: /home/jenkins/workspace/pipeline@tmp/durable-34c21b81/script.sh: Permission denied
  </code></pre>
  
  <p>Here are some additional things that we configured / figured out:</p>
  
  <ol>
  <li><p>We are running the agent on a VM with RHEL</p></li>
  <li><p>We are using the <a href="https://wiki.jenkins.io/display/JENKINS/Docker+Plugin" rel="noreferrer">Docker Plugin</a> for Jenkins to start / manage the containers on a separate Jenkins agent</p></li>
  <li><p>We are spinning up the Docker container using the <code>Connect with ssh</code> method in the Jenkins plugin and use the <a href="https://hub.docker.com/r/jenkinsci/ssh-slave/" rel="noreferrer">jenkinsci/ssh-slave Docker image</a> </p></li>
  <li><p>Jenkins is using the <code>root</code> user in the Docker container (at least all files within <code>/home/jenkins/...</code> are created as root</p></li>
  <li><p>When we add a <code>sleep</code> step into the pipeline and <code>docker exec...</code> into the running container, we cannot execute a simple shell script as root, if we are trying to run it with <code>./script.sh</code> (even if we set proper file mode with <code>chmod +x script.sh</code> before) - we also get <code>sh: 1: permission denied</code>. But we can run the script, if we use <code>sh script.sh</code></p></li>
  <li><p>The <code>root</code> user inside the Docker container has a <code>bash</code> - whereas Jenkins is trying to run the script with <code>sh</code>.</p></li>
  <li><p>The error occurs no matter whether we check the <code>run privileged</code> flag in the Docker plugin's template configuration or not</p></li>
  </ol>
  
  <p>Things we already tried, but didn't work</p>
  
  <ol>
  <li><p>Changing the login shell of the <code>root</code> user in the Docker container to <code>/bin/sh</code></p></li>
  <li><p>Providing a shebang in the <code>sh</code> step, à la <pre>
  sh '''#!/bin/sh
  echo "hello world"
  '''
  </pre></p></li>
  <li><p>Setting the shell executor to <code>/bin/sh</code> in the Jenkins global configuration</p></li>
  <li><p>Changing the <code>Dockerfile</code> of the ssh-slave Docker image in such a way that the <code>ENTRYPOINT</code> does not run a <code>bash</code> script, but runs <code>/bin/sh</code> at the end</p></li>
  </ol>
  
  <p>Any help is appreciated!</p>