run jenkins pipeline agent with sudo

前端 未结 7 1590
一生所求
一生所求 2020-12-09 11:19

I have an Jenkins Server running in an docker container and have access to docker an the host system, so far it is working well. Now I want to set up a pipeline testing an s

相关标签:
7条回答
  • 2020-12-09 11:51

    You can work around that by:

    1- In your Dockerfile add jenkins to the sudoers file:

    RUN echo "jenkins ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers

    2- Add an extra step in your Jenkinsfile to give jenkins the right permissions to use docker:

    pipeline {
    
        agent none
    
        stages {
    
            stage("Fix the permission issue") {
    
                agent any
    
                steps {
                    sh "sudo chown root:jenkins /run/docker.sock"
                }
    
            }
    
            stage('Step 1') {
    
                agent {
                    docker {
                        image 'nezarfadle/tools'
                        reuseNode true
                    }
                }
    
                steps {
                    sh "ls /"
                }
    
            }
    
        }
    }
    
    0 讨论(0)
提交回复
热议问题