Skip to content

JAVA服务构建发布

创建一个流水线任务

  • 前面的配置无所谓,贴上我的配置

流水线基础配置

  • 先贴上流水线脚本
Groovy
def lastCommitMessage
def gitUrl = 'git@e.coding.net:xmlll/lailailai/lai-shop.git'
def branch = 'release/test'
def privateKey = 'ce9161b9-b5ae-4e7d-9f26-07f0a698ca03'
def remote = [:]
remote.name = 'development'
remote.host = '192.168.50.201'
remote.user = 'root'
remote.allowAnyHosts = true
def packageName = 'platform-2.0'
def localPackagePath = './shop-system/target/'
def remotePackagePath = "/root/application/platform/"

pipeline {
    agent any

    stages {
        stage('拉取代码') {
            steps {
                git branch: branch, credentialsId: privateKey, url: gitUrl
            }
        }
        stage('获取最后一次提交的消息') {
            steps {            
                script {
                    lastCommitMessage = sh(returnStdout: true, script: 'git log -1 --pretty=%B').trim()
                    echo "Last Commit Message: ${lastCommitMessage}"
                }
            }
        }
        stage('构建') {
            steps {
                withMaven(globalMavenSettingsConfig: '', jdk: 'JDK11', maven: 'mvn3.8.6') {
                    sh 'mvn clean install -Dmaven.test.skip=true'
                }
            }
        }
        stage('上传到服务器') {
            steps {
                withCredentials([sshUserPrivateKey(credentialsId: privateKey, keyFileVariable: 'identity')]) {
                    script {
                        remote.identityFile = identity
                        sshCommand remote: remote, command: "rm -rf ${remotePackagePath}${packageName}.jar"
                        dir(localPackagePath) {
                            sshPut remote: remote, from: "${packageName}.jar", into: "${remotePackagePath}"
                        }
                        sshCommand remote: remote, command: "${remotePackagePath}app.sh restart"
                    }
                }
                
            }
        }
        
    }
    post {
        success {
            wxwork(
                robot: 'CODING',
                type: 'markdown',
                text: [
                    "# [**${JOB_NAME}**](${JOB_URL})",
                    "> 发布结果:<font color='info'>**成功**</font>",
                    "> 构建时长:<font color='comment'>**${currentBuild.durationString}**</font>",
                    "> 本地更新:${lastCommitMessage}",
                    "> 构建ID:[${BUILD_DISPLAY_NAME}](${BUILD_URL})"
                ]
            )
        }
        failure {
            wxwork(
                robot: 'CODING',
                type: 'markdown',
                text: [
                    "# [**${JOB_NAME}**](${JOB_URL})",
                    "> 发布结果:<font color='warning'>**失败**</font>",
                    "> 构建时长:<font color='comment'>**${currentBuild.durationString}**</font>",
                    "> 本地更新:${lastCommitMessage}",
                    "> 构建ID:[${BUILD_DISPLAY_NAME}](${BUILD_URL})"
                ]
            )
        }
    }
}

DANGER

编译过程中,出现了open too many files问题,需要修改ulimit,设置最大打开文件数量

* soft nofile 65536
* hard nofile 65536

docker

ulimits:
  nofile:
      soft: 65536
      hard: 65536

TIP

至此已发布完成