jenkins 多环境部署

Last updated on November 22, 2024 pm

🧙 Questions

场景:使用同一个jenkins流水线,发布不同分支代码到不同环境

☄️ Ideas

创建流水线

20220930111317

添加环境变量

注意:环境变量一定要大写

20220930111648

多选内容,回车即可

20220930111714

编写脚本

注意:环境变量一定要加双引号

node {
   stage('get env') {
      echo 'env:'+"${ENV}"
   }
}
测试

20220930113425

选择自己的环境

20220930113502

通过环境变量,获取环境编码

20220930113521

编写脚本思路
node {
   stage('checkout') {
         git branch: "${ENV}",url: 'http://github.com/ispong/leo-spring.git',credentialsId: '8f91b161-5cce-479a-82af-123'
   }
   stage('build') {
         echo 'package ispong-admin'
         sh 'mvn clean package -DskipTests'
   }
   stage('deploy') {
         
      if('dev' == "${ENV}"){
          host = 'isxcode-dev'
      } else if('qa' == "${ENV}"){
          host = 'isxcode-qa'
      } else if('demo' == "${ENV}"){
          host = 'isxcode-demo'
      }
      sh 'scp ./target/leo-spring-0.0.1.jar ispong@'+ "$host" +':/data/leo-spring.jar'
      sh 'ssh ispong@'+ "$host" +' \'cd /data/ && bash deploy.sh\''
   }
}

jenkins 多环境部署
https://ispong.isxcode.com/kubernetes/jenkins/jenkins 多环境部署/
Author
ispong
Posted on
September 30, 2022
Licensed under