|
@@ -0,0 +1,80 @@
|
|
|
|
+pipeline{
|
|
|
|
+ agent any
|
|
|
|
+ environment {
|
|
|
|
+ // 目标主机
|
|
|
|
+ dsthost = "192.168.50.21"
|
|
|
|
+ // 目标目录
|
|
|
|
+ dstroot = "/opt/jenkins/wf-platform-equipment-automation"
|
|
|
|
+ // 凭证ID
|
|
|
|
+ credentials = 'jayhaw'
|
|
|
|
+ // Java 运行参数
|
|
|
|
+ java_opts = "-Xms512m -Xmx1024m"
|
|
|
|
+ }
|
|
|
|
+ options {
|
|
|
|
+ // 不允许同时执行流水线, 防止同时访问共享资源等
|
|
|
|
+ disableConcurrentBuilds()
|
|
|
|
+ // 显示具体的构建流程时间戳
|
|
|
|
+ timestamps()
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ stages{
|
|
|
|
+ stage('Prepare') {
|
|
|
|
+ steps{
|
|
|
|
+ echo "1. Prepare Stage"
|
|
|
|
+ checkout scm
|
|
|
|
+ //sh "echo $ref"
|
|
|
|
+ sh "printenv"
|
|
|
|
+ script {
|
|
|
|
+ sh 'ls -l'
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ stage('Maven'){
|
|
|
|
+ steps{
|
|
|
|
+ echo "2. Maven Stage"
|
|
|
|
+ withMaven(
|
|
|
|
+ globalMavenSettingsConfig: 'stongmaven'
|
|
|
|
+ ) {
|
|
|
|
+
|
|
|
|
+ // Run the maven build
|
|
|
|
+ sh "mvn clean install package -U -Dmaven.test.failure.ignore"
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+// script{
|
|
|
|
+ // //sh "cat /etc/os-release"
|
|
|
|
+ //
|
|
|
|
+ // sh "mvn -Dmaven.test.failure.ignore clean package"
|
|
|
|
+ // }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ stage('Deploy'){
|
|
|
|
+ steps{
|
|
|
|
+ echo "3. Deploy Stage"
|
|
|
|
+ script{
|
|
|
|
+ def _pom = readMavenPom file: 'pom.xml'
|
|
|
|
+ sh "echo ${_pom.getVersion()}"
|
|
|
|
+ _version = _pom.getVersion()
|
|
|
|
+ _artifactId = _pom.getArtifactId()
|
|
|
|
+ sh "sed -i 's/<API_NAME>/${_artifactId}-${_version}/' Launch.sh"
|
|
|
|
+ sh "sed -i 's/<JAVA_OPTS>/${java_opts}/' Launch.sh"
|
|
|
|
+ //sh "scp hello-0.0.1-SNAPSHOT.jar"
|
|
|
|
+ withCredentials([usernamePassword(credentialsId: 'stong_test_jenkins', passwordVariable: 'PASSWORD', usernameVariable: 'USERNAME')]) {
|
|
|
|
+ def remote = [:]
|
|
|
|
+ remote.name = "dest"
|
|
|
|
+ remote.host = env.dsthost
|
|
|
|
+ remote.allowAnyHosts = true
|
|
|
|
+ remote.user = USERNAME
|
|
|
|
+ remote.password = PASSWORD
|
|
|
|
+ sshCommand remote: remote, command: "mkdir -p ${env.dstroot}"
|
|
|
|
+ sshPut remote: remote, from: 'Launch.sh', into: "${env.dstroot}"
|
|
|
|
+ sshPut remote: remote, from: "target/app.jar", into: "${env.dstroot}"
|
|
|
|
+ sshCommand remote: remote, command: "chmod +x ${env.dstroot}/Launch.sh"
|
|
|
|
+ sshCommand remote: remote, command: "cd ${env.dstroot} && ./Launch.sh restart"
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+}
|