在 Windows 上构建 Jenkins 期间将文件复制到其他目录

问题描述 投票:0回答:2

我正在尝试做一些看起来很基本但给我带来很多麻烦的事情。我正在尝试将构建的 jar 文件复制到不同的目录中,但构建在该步骤中始终失败。这是我的 Jenkinsfile,底部的“复制”步骤导致了失败。

pipeline {
  agent any
  stages {
    stage("Clean Up"){
      steps{
        deleteDir()
      }
    }
    stage("Clone Repo"){
      steps {
        bat "git clone https://github.com/CBoton/spring-boot-hello-world.git"
      }
    }
    stage("Build"){
      steps {
        dir("spring-boot-hello-world") {
          bat "mvn clean install"
        }
      }
    }
    stage("Test") {
      steps {
        dir("spring-boot-hello-world") {
          bat "mvn test"
        }
      }
    }
    stage("Package") {
        steps {
          dir("spring-boot-hello-world") {
            bat "mvn package"
        }
        }
        post {
          success {
            dir("spring-boot-hello-world") {
            archiveArtifacts 'target/*.jar'
          }
        }
      }
    }
    stage("Copy"){
      steps {
        dir("spring-boot-hello-world"){
          bat ("copy target/*.jar C:\\Users\\Curti\\Downloads")
        }
      }
    }
  }
}

我现在如何产生以下错误

C:\ProgramData\Jenkins\.jenkins\workspace\spring\spring-boot-hello-world>copy target/*.jar C:\Users\Curti\Downloads 


The syntax of the command is incorrect.

我已经尝试了许多路径变体,但无法让它工作。这开始让我发疯,因为它看起来是如此简单。任何帮助将不胜感激。

windows jenkins continuous-integration
2个回答
0
投票

@ycr,我试图在没有插件的情况下完成此操作,但最终文件操作插件起作用了,谢谢。我的新复制步骤看起来像

stage("Copy"){
      steps {
        fileOperations([fileCopyOperation(
        excludes: '',
        flattenFiles: false,
        includes: '**/*.jar',
        targetLocation: "C:\\output"
        )])
      }
}

0
投票

另一个选项是创建 powershell 构建步骤或构建后操作,并使用它来复制项目:

Copy-Item -Path “target\*.jar” -Destination “C:\Users\Curti\Downloads” -Recurse

© www.soinside.com 2019 - 2024. All rights reserved.