Jenkins on docker 编译一个maven java app.

本文简述如何用Jenkins 来自动编译一个java maven 项目。

  1. 在安装有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   
  1. 查看初始安装密码(78位container id 缩写)
#  docker exec -it 78 cat /var/jenkins_home/secrets/initialAdminPassword
06726df821f542d6a5e6a9bf220a0a6c
  1. 访问启动的Jenkins, 并根据wizard填入上面密码, 默认安装配置完毕
    http://xx.xx.xx.xx:8080

  2. git clone 你的maven project 到/home映射的path.

  3. 在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' 
            }
        }
    }
}
  1. git add . && git commit -m "Add initial Jenkinsfile"

  2. 创建 Pipeline project in Jenkins
    https://jenkins.io/doc/tutorials/build-a-java-app-with-maven/#create-your-pipeline-project-in-jenkins

  3. 点击左边 open blue ocean, 并开始RUN

image.png
  1. 关键配置如图
Jenkins on docker 编译一个maven java app._第1张图片
image.png

end.

REF: https://jenkins.io/doc/tutorials/build-a-java-app-with-maven/#create-your-pipeline-project-in-jenkins

你可能感兴趣的:(Jenkins on docker 编译一个maven java app.)