Skip to content

Commit

Permalink
feat($module=convention/core): 🎉 完成 持续集成的 Jenkins 部署等相关功能
Browse files Browse the repository at this point in the history
- 待改进:
  - 单元测试的集成

- ref #2
  • Loading branch information
o-w-o committed Nov 9, 2019
1 parent 2f3c9d8 commit bd6fbdd
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@ ENTRYPOINT java \
-Djava.security.egd=file:/dev/./urandom \
-jar /opt/app.jar

# 使用端口 80
# 使用端口 8080
EXPOSE 8080
62 changes: 62 additions & 0 deletions Jenkinsfile
Original file line number Diff line number Diff line change
@@ -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 "确认要部署线上环境吗?"
}
}
}
}

0 comments on commit bd6fbdd

Please sign in to comment.