Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-47389

sh step within container step does not work when user is non-root

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Not A Defect
    • Icon: Minor Minor
    • kubernetes-plugin
    • None
    • Jenkins 2.73.1, Kubernetes Plugin 1.0, Kubernetes 1.7.4

      Attempting to execute sh command within container step fails when the image user is not root.

      Replicate by running pipeline:

      podTemplate(name: 'my-pod', label: 'my-pod',
        containers: [
          containerTemplate(name: 'kubectl-cmd', 
                            image: 'wernight/kubectl:1.6.4',
                            ttyEnabled: true, 
                            command: 'cat', args:null)]) {
            node('my-pod') {
              stage('Test command') {
                container('kubectl-cmd') {
                  sh 'whoami'
                }
              }
            }
      } 

      `sh 'whoami'` does not successfully run, and the job fails with message: "ERROR: script returned exit code -2 "

      The image being run is here.

      I created a modified version of the image where simply "User kubectl" is removed. The job then runs as expected.

       

       

            Unassigned Unassigned
            willmore Chris Willmore
            Votes:
            5 Vote for this issue
            Watchers:
            11 Start watching this issue

              Created:
              Updated:
              Resolved: