支持开发环境远程部署
This commit is contained in:
+7
-4
@@ -36,7 +36,7 @@ pipeline {
|
||||
parameters {
|
||||
string(name: 'SOURCE_COMMIT', defaultValue: '', description: '必须构建的 Git commit;通常由总控 Job 传入')
|
||||
string(name: 'IMAGE_TAG', defaultValue: '', description: '不可变镜像标签;通常使用 Git commit 前 12 位')
|
||||
choice(name: 'ENVIRONMENT', choices: ['test', 'staging', 'production'], description: '部署环境')
|
||||
choice(name: 'ENVIRONMENT', choices: ['test', 'development', 'staging', 'production'], description: '部署环境')
|
||||
booleanParam(name: 'DEPLOY', defaultValue: false, description: '构建成功后是否部署本服务')
|
||||
booleanParam(name: 'SKIP_TESTS', defaultValue: false, description: '是否跳过测试')
|
||||
string(name: 'IMAGE_REPOSITORY', defaultValue: 'baiyue-firstleg-test', description: '镜像仓库基础路径,不包含服务名和标签')
|
||||
@@ -47,6 +47,9 @@ pipeline {
|
||||
REGISTRY_CREDENTIALS = 'gitea-test-token'
|
||||
MAVEN_SETTINGS = 'deploy/maven/settings-cn.xml'
|
||||
MAVEN_OPTS = '-Dfile.encoding=UTF-8 -Dmaven.wagon.http.retryHandler.count=3'
|
||||
DEVELOPMENT_SSH_TARGET = 'deploy@172.31.198.8'
|
||||
DEVELOPMENT_SSH_KEY = '/var/jenkins_home/.ssh/dev_deploy'
|
||||
DEVELOPMENT_DEPLOY_DIR = '/opt/firstleg/application'
|
||||
}
|
||||
|
||||
stages {
|
||||
@@ -81,7 +84,7 @@ pipeline {
|
||||
if (!imageRepository || imageRepository.contains('://')) {
|
||||
error('IMAGE_REPOSITORY 不能为空且不能包含 http:// 或 https://')
|
||||
}
|
||||
if (params.ENVIRONMENT != 'test' && !imageRepository.contains('/')) {
|
||||
if (!['development', 'test'].contains(params.ENVIRONMENT) && !imageRepository.contains('/')) {
|
||||
error('预发布/生产环境 IMAGE_REPOSITORY 必须使用 host[:port]/owner/image 格式')
|
||||
}
|
||||
|
||||
@@ -137,8 +140,8 @@ pipeline {
|
||||
sh "mkdir -p '${contextDir}' && cp -f '${jar}' '${contextDir}/app.jar'"
|
||||
sh "docker build -f deploy/docker/Dockerfile --build-arg BASE_IMAGE=${params.DOCKER_BASE_IMAGE} --build-arg JAR_FILE=app.jar -t ${image} '${contextDir}'"
|
||||
|
||||
if (params.ENVIRONMENT == 'test') {
|
||||
echo "测试镜像已保存在当前 Docker 节点:${image}"
|
||||
if (['development', 'test'].contains(params.ENVIRONMENT)) {
|
||||
echo "${params.ENVIRONMENT} 镜像已保存在当前 Docker 节点:${image}"
|
||||
} else {
|
||||
String registryHost = env.RESOLVED_IMAGE_REPOSITORY.tokenize('/')[0]
|
||||
withCredentials([usernamePassword(credentialsId: env.REGISTRY_CREDENTIALS, usernameVariable: 'REGISTRY_USER', passwordVariable: 'REGISTRY_PASSWORD')]) {
|
||||
|
||||
Reference in New Issue
Block a user