首页 > 解决方案 > 将当前构建的工件复制到服务器位置的 Jenkins 管道脚本

问题描述

我想创建一个 Jenkins 作业,它执行以下操作:Git>Mvn build> 将 jar 复制到服务器的某个位置。

所以这可以使用一个工作或两个工作来完成?或者哪种是首选方式,管道是否优于创建 maven 作业?

我已经创建了这个管道脚本,但这不会将当前构建 jar 复制到服务器位置,它会复制以前的构建工件 jar。

node {
   def mvnHome
   stage('Preparation') { // for display purposes
      // Get some code from a GitHub repository
  git 'git@github.pie.ABC.com:abcdef/BoltRepo.git'
   mvnHome = tool 'M2'
   }
   stage('Build') {
      // Run the maven build
      if (isUnix()) {
         sh "'${mvnHome}/bin/mvn' -Dmaven.test.failure.ignore clean     package"
      } else {
         bat(/"${mvnHome}binmvn" -Dmaven.test.failure.ignore clean     package/)
      }
   }
   stage('Results') {
      archiveArtifacts 'target/*/BoltRepo*.jar'
   }

   stage('Deploy Artifact') {
    copyArtifacts(
          projectName: currentBuild.projectName,
          filter: 'target/*/BoltRepo*.jar',
          fingerprintArtifacts: true,
          target:     '/ngs/app/boltd/bolt/bolt_components/bolt_provision/test',
          flatten: true        )
   }
 }


What is the best way of achieving this.

标签: jenkinsjenkins-pipeline

解决方案


我以前没有使用过管道,但是我已经使用作业配置中“构建后操作”中的“ArtifactDeployer”完成了您想要的操作注意:您需要安装“Artifact Deployer Plug-in”


推荐阅读