1-创建pipeline工程
2-credentialsId(凭证) 配置
- 效果
3-pipeline 脚本
pipeline {
agent any
parameters {
gitParameter branchFilter: 'origin/(.*)', defaultValue: 'developer', name: 'BRANCH', type: 'PT_BRANCH',description:'请选择分支进行部署,默认是developer'
}
stages {
stage('Checkout') {
steps {
echo '开始拉取代码.....git branch: "${params.BRANCH}",'
git branch: "${params.BRANCH}", credentialsId: 'git', url: 'xxx:tanmo_crm/tmrm-product-search.git'
}
}
stage('Build') {
steps {
echo '开始执行打包操作.......'
sh 'mvn clean package -U'
}
}
stage('CopyJar') {
steps {
sh 'scp ${WORKSPACE}/tmrm-product-search-service/target/tmrm-product-search-service.jar root@${RemoteIp}:/data/test_env_project_war/online_war'
sh 'scp ${WORKSPACE}/tmrm-product-search-web/target/tmrm-product-search-web.jar root@${RemoteIp}:/data/test_env_project_war/online_war'
sh 'scp ${WORKSPACE}/tmrm-product-search-business-service/target/tmrm-product-search-business-service.jar root@${RemoteIp}:/data/test_env_project_war/online_war'
}
}
stage('Deploy') {
steps {
//sh 'ssh root@10.50.12.8 "sh /opt/wars/{远程服务器的一个文件夹}/deploy.sh" '
echo '测活成功'
script {
if ("${ServerName}" == "tmrm-product-search-web") {
sh 'ssh root@${RemoteIp} "sh /data/webapps/scripts/product-search-web.sh"'
} else if ("${ServerName}" == "tmrm-product-search-service") {
sh 'echo ${ServerName}'
sh 'ssh root@${RemoteIp} "sh /data/webapps/scripts/product-search-service.sh"'
}else if ("${ServerName}" == "tmrm-product-search-business-service") {
sh 'ssh root@${RemoteIp} "sh /data/webapps/scripts/product-search-business.sh"'
} else if ("${ServerName}" == "all") {
sh 'echo ${ServerName}'
sh 'ssh root@${RemoteIp} "sh /data/webapps/scripts/product-search-web.sh"'
sh 'ssh root@${RemoteIp} "sh /data/webapps/scripts/product-search-service.sh"'
sh 'ssh root@${RemoteIp} "sh /data/webapps/scripts/product-search-business.sh"'
}
}
}
}
}
}
pipeline {
agent any
parameters {
gitParameter branchFilter: 'origin/(.*)', defaultValue: 'developer', name: 'BRANCH', type: 'PT_BRANCH',description:'请选择分支进行部署,默认是developer'
}
stages {
stage('Checkout') {
steps {
echo '开始拉取代码.....git branch: "${params.BRANCH}",'
git branch: "${params.BRANCH}", credentialsId: 'git', url: 'xxx:tanmo_crm/tmrm-product-search.git'
}
}
stage('Build') {
steps {
echo '开始执行打包操作.......'
sh 'mvn clean package -U'
}
}
stage('CopyJar') {
steps {
sh 'scp ${WORKSPACE}/tmrm-product-search-service/target/tmrm-product-search-service.jar root@${RemoteIp}:/data/test_env_project_war/online_war'
sh 'scp ${WORKSPACE}/tmrm-product-search-web/target/tmrm-product-search-web.jar root@${RemoteIp}:/data/test_env_project_war/online_war'
sh 'scp ${WORKSPACE}/tmrm-product-search-business-service/target/tmrm-product-search-business-service.jar root@${RemoteIp}:/data/test_env_project_war/online_war'
}
}
stage('Deploy') {
steps {
//sh 'ssh root@10.50.12.8 "sh /opt/wars/{远程服务器的一个文件夹}/deploy.sh" '
echo '测活成功'
script {
if ("${ServerName}" == "tmrm-product-search-web") {
sh 'ssh root@${RemoteIp} "sh /data/webapps/scripts/product-search-web.sh"'
} else if ("${ServerName}" == "tmrm-product-search-service") {
sh 'echo ${ServerName}'
sh 'ssh root@${RemoteIp} "sh /data/webapps/scripts/product-search-service.sh"'
}else if ("${ServerName}" == "tmrm-product-search-business-service") {
sh 'ssh root@${RemoteIp} "sh /data/webapps/scripts/product-search-business.sh"'
} else if ("${ServerName}" == "all") {
sh 'echo ${ServerName}'
sh 'ssh root@${RemoteIp} "sh /data/webapps/scripts/product-search-web.sh"'
sh 'ssh root@${RemoteIp} "sh /data/webapps/scripts/product-search-service.sh"'
sh 'ssh root@${RemoteIp} "sh /data/webapps/scripts/product-search-business.sh"'
}
}
}
}
}
}