From c6ad152a5f5a4d709c0e48d712bc990e82944076 Mon Sep 17 00:00:00 2001 From: o-w-o Date: Fri, 8 Nov 2019 21:08:42 +0800 Subject: [PATCH] =?UTF-8?q?feat($module=3Dconvention/core):=20:tada:=20?= =?UTF-8?q?=E5=AE=8C=E6=88=90=20=E6=8C=81=E7=BB=AD=E9=9B=86=E6=88=90?= =?UTF-8?q?=E7=9A=84=20Jenkins=20=E9=83=A8=E7=BD=B2=E7=AD=89=E7=9B=B8?= =?UTF-8?q?=E5=85=B3=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 待改进: - 单元测试的集成 - ref #2 --- Dockerfile | 2 +- Jenkinsfile | 61 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 62 insertions(+), 1 deletion(-) create mode 100644 Jenkinsfile diff --git a/Dockerfile b/Dockerfile index 6d3cdeb..06b0e51 100644 --- a/Dockerfile +++ b/Dockerfile @@ -16,5 +16,5 @@ ENTRYPOINT java \ -Djava.security.egd=file:/dev/./urandom \ -jar /opt/app.jar -# 使用端口 80 +# 使用端口 8080 EXPOSE 8080 diff --git a/Jenkinsfile b/Jenkinsfile new file mode 100644 index 0000000..0c7d056 --- /dev/null +++ b/Jenkinsfile @@ -0,0 +1,61 @@ +pipeline { + agent { + docker { + image 'maven:3.6-alpine' + args '-u root -v /var/mvn/repos:/root/.m2' + } + + } + + stages { + stage('Prepare') { + steps { + echo "1 Prepare Stage" + + echo '1.0 检验 mvn 版本' + sh 'mvn -v' + + echo '1.1 获取 项目 pom.xml 中的版本号' + + script { + def __buildTag__ = sh "mvn -q -Dexec.executable='echo' -Dexec.args='${projects.version}' --non-recursive org.codehaus.mojo:exec-maven-plugin:1.3.1:exec" + def buildTag = __buildTag__.trim() + } + + echo buildTag + input('构建版本号为【' + buildTag + '】, 确定吗?') + } + } + stage('Test') { + steps { + echo "2.Test Stage" + } + } + stage('Build') { + steps { + echo "3 Build Docker Image Stage" + + echo '3.0 使用 mvn 打包' + sh 'mvn clean package -Dmaven.test.skip=true' + + echo '3.1 使用 mvn 构建 docker 镜像' + sh 'mvn dockerfile:build -Dmaven.test.skip=true' + } + } + stage('Push') { + steps { + echo "4.Push Docker Image Stage" + withCredentials([usernamePassword(credentialsId: 'aliDockerRegistry', passwordVariable: 'dockerHubPassword', usernameVariable: 'dockerHubUser')]) { + sh "docker login -u ${dockerHubUser} -p ${dockerHubPassword}" + sh "docker push registry.cn-beijing.aliyuncs.com/o-w-o/api:${buildTag}" + } + } + } + stage('Deploy') { + steps { + echo "5. Deploy Stage" + input "确认要部署线上环境吗?" + } + } + } +}