我想,如果你会使用管道工作,这将是一件好事。 在这里,您可以检查与评论
pipeline {
stages {
stage('Build') {
agent { //here we select only docker build agents
docker {
image 'maven:latest' //container will start from this image
args '-v /root/.m2:/root/.m2' //here you can map local maven repo, this let you to reuse local artifacts
}
}
steps {
sh 'mvn -B -DskipTests clean package' //this command will be executed inside maven container
}
}
stage('Test') { //on this stage New container will be created, but current pipeline workspace will be remounted to it automatically
agent {
docker {
image 'maven:latest'
args '-v /root/.m2:/root/.m2'
}
}
steps {
sh 'mvn test'
}
}
stage ('Build docker image') { //here you can check how you can build even docker images inside container
agent {
docker {
image 'maven:latest'
args '-v /root/.m2:/root/.m2 -v /var/run/docker.sock:/var/run/docker.sock' //here we expose docker socket to container. Now we can build docker images in the same way as on host machine where docker daemon is installed
}
}
steps {
sh 'mvn -Ddocker.skip=false -Ddocker.host=unix:///var/run/docker.sock docker:build' //example of how to build docker image with pom.xml and fabric8 plugin
}
}
}
}
即使詹金斯本身与来自主机贴片jenkins_home容器中运行这工作,我的例子。
请让我知道,如果我可以提供更多有用的细节从我的经验给你