Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/amazon-s3/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在Jenkins管道中使用s3upload上传多个文件_Jenkins_Amazon S3_Jenkins Plugins_Jenkins Pipeline - Fatal编程技术网

在Jenkins管道中使用s3upload上传多个文件

在Jenkins管道中使用s3upload上传多个文件,jenkins,amazon-s3,jenkins-plugins,jenkins-pipeline,Jenkins,Amazon S3,Jenkins Plugins,Jenkins Pipeline,我们可以使用in-Jenkins文件将多个文件(而不是整个文件夹)上载到S3吗 我试图使用s3Upload功能将根目录中的所有rpm文件(*.rpm)上载到S3 请参阅以下链接。在此,请参阅“排除和包括过滤器的使用”一节 下面是一种上载特定类型的多个文件的方法 如果只想上载具有特定扩展名的文件,则需要首先排除所有文件,然后重新包含具有特定扩展名的文件。此命令将仅上载以.jpg结尾的文件: aws s3 cp /tmp/foo/ s3://bucket/ --recursive --exclude

我们可以使用in-Jenkins文件将多个文件(而不是整个文件夹)上载到S3吗


我试图使用
s3Upload
功能将根目录中的所有rpm文件(
*.rpm
)上载到S3

请参阅以下链接。在此,请参阅“排除和包括过滤器的使用”一节

下面是一种上载特定类型的多个文件的方法

如果只想上载具有特定扩展名的文件,则需要首先排除所有文件,然后重新包含具有特定扩展名的文件。此命令将仅上载以.jpg结尾的文件:

aws s3 cp /tmp/foo/ s3://bucket/ --recursive --exclude "*" --include "*.jpg"

这适用于AWS命令行界面

FindFile解决了这个问题。下面是用于相同目的的代码段

files = findFiles(glob: '*.rpm')

  files.each { 
      println "RPM:  ${it}"
      withAWS(credentials: '****************'){
       s3Upload(file:"${it}", bucket:'rpm-repo', path:"${bucket_path}")
        }
    }

您可以使用以下命令在一行中上载所有文件

  s3Upload(bucket:"my-bucket", path:'path/to/targetFolder/', includePathPattern:'**/*.svg', workingDir:'dist')
进一步说明,您可以基于以下两种可能性创建自己的筛选

1.包含某个扩展名的所有文件

s3Upload(bucket:"my-bucket", path:'path/to/targetFolder/', includePathPattern:'**/*.svg', workingDir:'dist')
s3Upload(bucket:"my-bucket", path:'path/to/targetFolder/', includePathPattern:'**/*', workingDir:'dist', excludePathPattern:'**/*.svg')
2.包括除特定文件扩展名以外的所有文件

s3Upload(bucket:"my-bucket", path:'path/to/targetFolder/', includePathPattern:'**/*.svg', workingDir:'dist')
s3Upload(bucket:"my-bucket", path:'path/to/targetFolder/', includePathPattern:'**/*', workingDir:'dist', excludePathPattern:'**/*.svg')

参考:(在s3Upload下选中)

对于管道,您需要在
脚本中包装迭代,如

pipeline {
  environment {
    // Extract concise branch name.
    BRANCH = GIT_BRANCH.substring(GIT_BRANCH.lastIndexOf('/') + 1, GIT_BRANCH.length())
  }
  ...
  post {
    success {
      script {
        def artifacts = ['file1', 'dir2/file3']
        artifacts.each {
          withAWS(credentials:'my-aws-token', region:'eu-west-1') {
            s3Upload(
              file: "build/${it}",
              bucket: 'my-artifacts',
              path: 'my-repo/',
              metadatas: ["repo:${env.JOB_NAME}", "branch:${env.BRANCH}", "commit:${env.GIT_COMMIT}"]
            )
          }
        }
      }
    }
  }
}

还有。。?发生了什么?IIRC
s3upload
仅支持单个文件或目录。因此,要么使用
findFiles('*.rpm')
对它们进行迭代,然后对每个文件调用
s3Upload
,要么上传完整的目录。让我马上试试。@StephenKing finFiles有效
files=findFiles(glob:'*.rpm')files.each{println“rpm:${it}”with aws(凭证:'********'){//s3Upload(文件:${it}),bucket:'bucket',path:${bucket_path}}
此答案针对的是
aws
CLI。我假设OP意味着AWS插件的步骤。@StephenKing是对的。s3Upload适用于Jenkins管道步骤,根据s3Upload上提供的官方文档,s3Upload支持上载单个文件或上载整个目录(包括所有子文件夹)。因此,我尝试给出一个替代解决方案。我如何执行分配给运行Jenkins管道的节点的IAM角色?没有证件