debian

Debian JSP应用如何进行持续集成

小樊
34
2025-12-12 18:53:21
栏目: 编程语言

在 Debian 上为 JSP 应用搭建持续集成

一 架构与工具选型

二 在 Debian 上部署 Jenkins

三 创建 Jenkins 任务与 Webhook 触发

四 示例 Jenkinsfile 与 Tomcat 部署

pipeline {
  agent any
  tools {
    maven 'Maven-3'   // 在 Global Tool Configuration 中定义的 Maven 名称
    jdk   'OpenJDK-11' // 在 Global Tool Configuration 中定义的 JDK 名称
  }
  stages {
    stage('Checkout') {
      steps {
        git url: 'https://github.com/your-org/your-jsp-app.git', branch: 'main'
      }
    }
    stage('Build') {
      steps {
        sh 'mvn -B -DskipTests clean package'
      }
    }
    stage('Test') {
      steps {
        sh 'mvn test'
      }
      post {
        always {
          junit 'target/surefire-reports/*.xml'
        }
      }
    }
    stage('Deploy to Tomcat') {
      steps {
        script {
          def war = findFiles(glob: 'target/*.war')[0].path
          // 方式A:使用 curl 调用 Manager API(示例,请替换为你的实际地址/凭据)
          sh """
            curl --upload-file '${war}' \
              --user 'tomcat:tomcat' \
              'http://tomcat.example.com:8080/manager/text/deploy?path=/your-app&update=true'
          """
          // 方式B(可选):使用 Tomcat Maven Plugin
          // sh 'mvn tomcat7:deploy -DskipTests'
        }
      }
    }
  }
  post {
    success {
      echo 'Build and deploy succeeded.'
    }
    failure {
      echo 'Build or deploy failed.'
    }
  }
}

五 最佳实践与扩展

0
看了该问题的人还看了