Jenkinsfile: permission denied when running sh-step in Docker container

I have a problem starting a simple one Jenkinsfile- for example,

pipeline {
    agent { label 'ssh-slave' } 
    stages {
        stage('Shell Test') {
            steps {
                sh 'echo "Hello World"'
            }
        }
    }
}

The Jenkins log files on the master page show that the container was launched successfully, but the build job crashes with a message like

sh: 1: /home/jenkins/workspace/pipeline@tmp/durable-34c21b81/script.sh: Permission denied

Here are some additional things we have configured / understood:

  • We run the agent in a virtual machine with RHEL

  • We use the Jenkins Docker Plugin to run / manage containers on a separate Jenkins agent

  • We deploy the Docker container using the method Connect with sshin the Jenkins plugin and use jenkinsci / ssh-slave Docker image

  • Jenkins uses the user rootin the Docker container (at least all files in /home/jenkins/...are created as root

  • sleep docker exec... , script root, ./script.sh ( chmod +x script.sh ) - sh: 1: permission denied. script, sh script.sh

  • root Docker bash, script sh.

  • , run privileged Docker

, ,

  • root Docker /bin/sh

  • shebang sh, la

    sh '''#!/bin/sh
    echo "hello world"
    '''
    
  • /bin/sh Jenkins

  • Dockerfile ssh-slave , ENTRYPOINT bash script, /bin/sh

!

+4
1

, /home/jenkins noexec:

$ mount
/dev/mapper/rhel-var on /home/jenkins type xfs (rw,nosuid,nodev,noexec,relatime,seclabel,attr2,inode64,noquota)

, /var noexec (/var - ...):

$ mount
/dev/mapper/rhel-var on /var type xfs (rw,nosuid,nodev,noexec,relatime,seclabel,attr2,inode64,noquota)

, , /var

sudo mount -o remount,exec /var

.

+2

Source: https://habr.com/ru/post/1688972/


All Articles