Skip to content

Commit

Permalink
fix($module=convention/core): 🐛 Jenkinsfile debug
Browse files Browse the repository at this point in the history
- ref #2
  • Loading branch information
o-w-o committed Nov 11, 2019
1 parent d79d679 commit 09f2acf
Showing 1 changed file with 24 additions and 12 deletions.
36 changes: 24 additions & 12 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ pipeline {

environment {
DOCKER_REGISTRY_NAMESPACE = 'registry.cn-beijing.aliyuncs.com/o-w-o'
TAGGED_DOCKER_IMG = "${env.DOCKER_REGISTRY_NAMESPACE}/api:latest"
}

parameters {
string(name: 'TAGGED_DOCKER_IMG', defaultValue: "${env.DOCKER_REGISTRY_NAMESPACE}/api:latest", description: '已经 build 并 push 成功的项目镜像名')
booleanParam(name: 'ENABLE_DEBUG', defaultValue: true, description: '开启 DEBUG 模式')
}

stages {
Expand All @@ -29,16 +30,27 @@ pipeline {
JAR_FILENAME = sh(returnStdout: true, script: "mvn -q -N -Dexec.executable='echo' -Dexec.args='\${project.build.finalName}' exec:exec").trim()
JAR_PATH = "target/${JAR_FILENAME}.jar"

println "【 IMG_BUILD_TAG 】-> ${IMG_BUILD_TAG}"
println "【 JAR_FILENAME 】-> ${JAR_FILENAME}"
println "【 JAR_PATH 】-> ${JAR_PATH}"
env.TAGGED_DOCKER_IMG = "${env.DOCKER_REGISTRY_NAMESPACE}/api:${IMG_BUILD_TAG}"
println env.TAGGED_DOCKER_IMG
}

}
}
stage('Prepare:Debug') {
when {
expression { return params.ENABLE_DEBUG }
}
steps {
input('构建版本号为【' + IMG_BUILD_TAG + '】, 确定吗?')

script {
params.TAGGED_DOCKER_IMG = "${env.DOCKER_REGISTRY_NAMESPACE}/api:${IMG_BUILD_TAG}"
}
}
}
stage('Prepare:Post') {
when {
expression { return !params.ENABLE_DEBUG }
}
steps {
println "【 IMG_BUILD_TAG 】-> ${IMG_BUILD_TAG}"
println "【 JAR_FILENAME 】-> ${JAR_FILENAME}"
println "【 JAR_PATH 】-> ${JAR_PATH}"
}
}
stage('Build') {
Expand Down Expand Up @@ -72,10 +84,10 @@ pipeline {
sh "docker login -u ${dockerHubUser} -p ${dockerHubPassword} registry.cn-beijing.aliyuncs.com"

echo "4.2 构建 Image"
sh "docker build --build-arg JAR_PATH=${JAR_PATH} --tag ${params.TAGGED_DOCKER_IMG} ."
sh "docker build --build-arg JAR_PATH=${JAR_PATH} --tag ${env.TAGGED_DOCKER_IMG} ."

echo "4.3 发布 Image"
sh "docker push ${params.TAGGED_DOCKER_IMG}"
sh "docker push ${env.TAGGED_DOCKER_IMG}"
}
}
}
Expand All @@ -102,7 +114,7 @@ pipeline {
echo "部署预处理异常 -> ${e.message}"
}

sshCommand remote: remote, command: "docker run -it --rm --net=host --name=api -e JAVA_OPTS='-Xms128m -Xmx256m' ${params.TAGGED_DOCKER_IMG}"
sshCommand remote: remote, command: "docker run -it --rm --net=host --name=api -e JAVA_OPTS='-Xms128m -Xmx256m' ${env.TAGGED_DOCKER_IMG}"
}
}
}
Expand Down

0 comments on commit 09f2acf

Please sign in to comment.