jenkins pipline

https://www.jenkins.io/zh/doc/pipeline/tour/hello-world/

https://www.jianshu.com/p/f1167e8850cd

 

maven项目jenkinsfile

目标是n多个maven项目公用一个jenkins模板文件,然后通过改环境变量的方式去发版

pipeline {
   agent any
   environment  {
        git = "http://xx"
        catalog = 'test'
        subpath = 't'
        jar = ''
        ip = ''
        port = ''
        jvm = " -jar /root/$subpath/target/$jar --server.port=$port"
        cmd = 'curl -s http://master/cds/service/run.sh | sh -x -s restart "$jvm"'
    }

   tools {
      maven "maven"
   }

   stages {
      stage('Build') {
         steps {
            git credentialsId: '', poll: false, url: "$git"
            sh "mvn clean package -P$catalog -pl $subpath -am -Dmaven.test.skip=true"
         }

         post {
            success {
               archiveArtifacts "$subpath/target/$jar"
               sshPublisher(publishers: [sshPublisherDesc(configName: "$ip", transfers: [sshTransfer(execCommand:"$cmd", sourceFiles: "$subpath/target/$jar")])])}
         }
      }
   }
}

  

posted @ 2020-05-13 10:58  jabbok  阅读(240)  评论(0编辑  收藏  举报