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..c435b55 --- /dev/null +++ b/Jenkinsfile @@ -0,0 +1,62 @@ +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 中的版本号' + sh 'sed -n "13p" pom.xml | sed "s/<\\/*version>//gi"' + + script { + def __buildTag__ = sh 'sed -n "13p" pom.xml | sed "s/<\\/*version>//gi"' + 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 "确认要部署线上环境吗?" + } + } + } +}