How to mount Jenkins workspace in docker container using Jenkins pipeline

前端 未结 4 1082
攒了一身酷
攒了一身酷 2020-12-13 20:34

I\'m using Jenkins in docker. The /var/jenkins_home is mounted on /var/jenkins-data on my host. My Jenkins can execute docker commands (mount of so

4条回答
  •  执念已碎
    2020-12-13 21:01

    pipeline {
    agent any
    stages {
        stage('Clone') {
            steps {
                git branch: 'master', url: 'https://github.com/lvthillo/maven-hello-world.git'
                stash name:'scm', includes:'*'
            }
        }
    
        stage('Build in Docker') {
            steps {
                unstash 'scm'
                script{
                    docker.image('maven:3.5.2').inside{ 
                        sh 'pwd'
                        sh 'mvn -v'
                        sh 'mvn clean install'
                    }
                }
            }
        }
    }
    }
    

    You can use this pipeline even with a multi-node setup. Docker plugin mounts your workspace as a docker workspace too.Hence, it is not necessary to mount any volume unless they are outside the workspace.

提交回复
热议问题