Jenkins-pipeline

一个标准的Jenkins流水线声明书文件

pipeline {
agent any
  options {
  //添加日志打印时间
  timestamps()
  //设置全局超时
  timeout(time: 10, unit: 'MINUTES')
  }
  parameters {
  string(name: 'WAR_NAME', defaultValue: 'app', description: 'war包名字')
  }
  environment{
  MAVEN_HOME = '/home/maven3.6.2'
  SVN_URL = 'https://xxxxx/xxxx/xxxxx'
  deploy_shell = 'hrysoft-dev/deploy.sh'
  }

  stages {

  stage('init project') {
    steps {
      script {
      deploy_sh=readFile encoding: 'utf-8', file: deploy_shell
      }
    }
  }

  stage('svn checkout'){
    steps {
      echo 'pull code'
      withCredentials([usernamePassword(credentialsId: '88-svn', passwordVariable: 'SVN_PASSWORD', usernameVariable: 'SVN_USERNAME')]) {
      sh 'svn co ${SVN_URL} . --username ${SVN_USERNAME} --password ${SVN_PASSWORD}'
      }
    }
  }

  stage('build project'){
    steps {
    echo 'mvn package'
    sh '$MAVEN_HOME/bin/mvn clean package'
    }
  }

  stage('deploy ssh') {
    steps {
    writeFile encoding: 'utf-8', file: 'deploy.sh', text: deploy_sh
      script {
        def remote = [:]
        remote.name = 'server'
        remote.host = '000.000.000.000'
        remote.allowAnyHosts = true
        withCredentials([usernamePassword(credentialsId: '121', passwordVariable: 'password', usernameVariable: 'username')]) {
        remote.user = "${username}"
        remote.password = "${password}"
        }
        sshPut remote:remote, from: 'deploy.sh', into: '.'
        sshPut remote:remote, from: 'hry_web_admin/target/admin.war', into: '.'
        sshCommand remote: remote, command: "chmod +x deploy.sh"
        //sshCommand remote: remote, command: "./deploy.sh"
        }
      }
    }
  }
}

posted @ 2020-07-10 11:24  逆天邪神-云撤  阅读(107)  评论(0)    收藏  举报