Jenkins文件使用S3FindFile在S3中查找文件
我想在Jenkinsfile(管道)中使用Jenkins文件使用S3FindFile在S3中查找文件,jenkins,jenkins-pipeline,jenkins-plugins,Jenkins,Jenkins Pipeline,Jenkins Plugins,我想在Jenkinsfile(管道)中使用s3findFile,在S3 bucket中搜索文件。我试着用下面的方法 steps { withCredentials([[ $class: 'AmazonWebServicesCredentialsBinding',credentialsId: 'jenkins-user-for-aws',accessKeyVariable: 'AWS_ACCESS_KEY_ID',secret
s3findFile
,在S3 bucket中搜索文件。我试着用下面的方法
steps {
withCredentials([[
$class: 'AmazonWebServicesCredentialsBinding',credentialsId: 'jenkins-user-for-aws',accessKeyVariable: 'AWS_ACCESS_KEY_ID',secretKeyVariable: 'AWS_SECRET_ACCESS_KEY'
]]) {
s3FindFiles(bucket:'my-bucket', path:'firmwares/', glob:'gwsw_*')
}
}
哪张照片
Searching s3://my-bucket/firmwares/ for glob:'gwsw_*'
Search complete
如何从中获取文件名
根据它返回的名称
,所以我尝试了
steps {
withCredentials([[
$class: 'AmazonWebServicesCredentialsBinding',credentialsId: 'jenkins-user-for-aws',accessKeyVariable: 'AWS_ACCESS_KEY_ID',secretKeyVariable: 'AWS_SECRET_ACCESS_KEY'
]]) {
files = s3FindFiles(bucket:'my-bucket', path:'firmwares/', glob:'gwsw_*')
echo files[0].name
}
}
但我犯了这个错误:
WorkflowScript: 256: Expected a step @ line 256, column 19.
files = s3FindFiles(bucket:'my-bucket', path:"firmwares/", glob:'gwsw_*')
返回具有以下属性的FileWrapper实例数组:
- 名称:路径的文件名部分(对于“path/to/my/file.ext”, 这将是“file.ext”)
- 路径:文件的完整路径,相对于 指定的路径(对于path=“path/to/”,文件的此属性 “路径/to/my/file.ext”将是“my/file.ext”)
- 目录:如果 是一个目录;false否则为长度:文件的长度(此 对于目录,始终为“0”)
- lastModified:最后一次修改 时间戳,从Unix纪元开始以毫秒为单位(对于目录,此值始终为“0”)
name_by_property = files[0].name
name_by_method = files[0].getName()
如果使用的是声明性管道
,则需要使用脚本
块包装代码:
steps {
withCredentials([[$class: 'AmazonWebServicesCredentialsBinding', credentialsId: 'jenkins-user-for-aws', accessKeyVariable: 'AWS_ACCESS_KEY_ID', secretKeyVariable: 'AWS_SECRET_ACCESS_KEY']]) {
script{
files = s3FindFiles(bucket:'my-bucket', path:'firmwares/', glob:'gwsw_*', onlyFiles: true)
// get the first name
println files[0].name
// iterate over all files
files.each { println "File name: ${it.name}, timestamp: ${it.lastModified}"}
}
}
}
出现WorkflowScript错误,已在我的问题中更新。@roy如果您使用的是声明性管道,则需要使用
script
标记包装代码,我已更新了我的答案,以仅包含脚本标记:script{files=s3FindFiles(bucket:'my-bucket',path:'firmware/',glob:'gwsw\*')echo文件[0]。name}
@roy此解决方案解决了您的问题吗?