本文简述如何用Jenkins 来自动编译一个java maven 项目。
- 在安装有docker 的机器上, 安装并运行Jenkins:
docker run -d -u root -p 8080:8080 -v /data/elk/jenkins-data:/var/jenkins_home -v /var/run/docker.sock:/var/run/docker.sock -v "$HOME":/home jenkinsci/blueocean
- 查看初始安装密码(78位container id 缩写)
# docker exec -it 78 cat /var/jenkins_home/secrets/initialAdminPassword
06726df821f542d6a5e6a9bf220a0a6c
-
访问启动的Jenkins, 并根据wizard填入上面密码, 默认安装配置完毕
http://xx.xx.xx.xx:8080 -
git clone 你的maven project 到/home映射的path.
-
在maven 本地clone根目录下写vi Jenkinsfile
注意配置maven仓库位置
pipeline {
agent {
docker {
image 'maven:3-alpine'
args '-v /root/.m2:/root/.m2'
}
}
stages {
stage('Build') {
steps {
sh 'mvn -B -DskipTests clean package'
}
}
stage('Test') {
steps {
sh 'mvn test'
}
post {
always {
junit 'target/surefire-reports/*.xml'
}
}
}
stage('Deliver') {
steps {
sh './jenkins/scripts/deliver.sh'
}
}
}
}
-
git add . && git commit -m "Add initial Jenkinsfile"
-
创建 Pipeline project in Jenkins
https://jenkins.io/doc/tutorials/build-a-java-app-with-maven/#create-your-pipeline-project-in-jenkins -
点击左边 open blue ocean, 并开始RUN
image.png
- 关键配置如图
image.png
end.
网友评论