代码拉取完成,页面将自动刷新
import java.time.LocalDateTime
import java.time.format.DateTimeFormatter
pipeline {
agent any
parameters {
string(name: 'profile', defaultValue: 'dev', description: 'Build environment')
string(name: 'dockerRepository', defaultValue: '47.97.206.189:5000', description: 'docker repository')
}
tools {
maven 'maven3.8.2'
jdk 'openjdk-jdk11'
}
environment {
orderCenterPath = 'business/order-center'
userCenterPath = 'business/user-center'
gatewayCenterPath = 'gateway/sc-gateway'
oauthCenterPath = 'gateway/oauth2'
kubectl = "kubectl --kubeconfig /var/jenkins_home/k8s/kubectl/config"
}
stages {
stage('Prepare') {
steps {
sh "mvn -P ${profile} clean validate compile test package"
script {
container_version = ":" + LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMddHHmmss"))
}
}
}
stage('Build') {
failFast true
parallel {
stage('Build order center') {
steps {
script {
def orderPom = readMavenPom file: "${orderCenterPath}/pom.xml"
userCenterJarName = "basic-${orderPom.artifactId}-${profile}"
userTag = "${dockerRepository}/${userCenterJarName}${container_version}"
}
sh "docker build --build-arg JAR_FILE=${userCenterJarName}.jar -t ${userCenterJarName} ${orderCenterPath}"
sh "docker tag ${userCenterJarName} ${userTag}"
sh "docker push ${userTag}"
}
}
stage('Build user center') {
steps {
script {
def userPom = readMavenPom file: "${userCenterPath}/pom.xml"
orderCenterJarName = "basic-${userPom.artifactId}-${profile}"
orderTag = "${dockerRepository}/${orderCenterJarName}${container_version}"
}
sh "docker build --build-arg JAR_FILE=${orderCenterJarName}.jar -t ${orderCenterJarName} ${userCenterPath}"
sh "docker tag ${orderCenterJarName} ${orderTag}"
sh "docker push ${orderTag}"
}
}
stage('Build gateway') {
steps {
script {
def gatewayPom = readMavenPom file: "${gatewayCenterPath}/pom.xml"
gatewayJarName = "basic-${gatewayPom.artifactId}-${profile}"
gatewayTag = "${dockerRepository}/${gatewayJarName}${container_version}"
}
sh "docker build --build-arg JAR_FILE=${gatewayJarName}.jar -t ${gatewayJarName} ${gatewayCenterPath}"
sh "docker tag ${gatewayJarName} ${gatewayTag}"
sh "docker push ${gatewayTag}"
}
}
stage('Build oauth2') {
steps {
script {
def oauthPom = readMavenPom file: "${oauthCenterPath}/pom.xml"
oauthJarName = "basic-${oauthPom.artifactId}-${profile}"
oauthTag = "${dockerRepository}/${oauthJarName}${container_version}"
}
sh "docker build --build-arg JAR_FILE=${oauthJarName}.jar -t ${oauthJarName} ${oauthCenterPath}"
sh "docker tag ${oauthJarName} ${oauthTag}"
sh "docker push ${oauthTag}"
}
}
}
}
stage("Deploy") {
steps {
script {
env.profile = profile
tempFileName = "kubernetes_temp.yaml"
// 设置版本号 解决k8s文件镜像不更新的问题
env.container_version = container_version
env.JAVA_OPTS = '-Xms512m -Xmx512m'
}
// 替换k8s文件中的环境变量
sh "envsubst < build/kubernetes-${profile}.yaml > ${tempFileName}"
script {
def file = readFile file: tempFileName
println file
}
sh "${kubectl} apply --record -f ${tempFileName}"
}
}
}
post {
always {
script {
def template = readFile file: 'build/jenkins-mail-template.html'
}
}
success {
script {
junit "**/target/surefire-reports/*.xml"
jacoco(
execPattern: '**/target/jacoco.exec',
classPattern: '**/classes',
exclusionPattern: '**/src/test*',
)
}
}
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。