我正在尝试将Lambda zip文件发布到s3-s3://my-aws-lambda/<projectName>/[release|SNAPSHOT]/
。下面定义的任务,publishToS3
失败,并显示消息
Caused by: java.io.FileNotFoundException: /Users/me/my-lambda/build/distributions
当我运行时
./gradlew clean build -x test -x release
感谢您的帮助。谢谢
task buildZip(type: Zip) {
from compileJava
from processResources
into('lib') {
from configurations.runtimeClasspath
}
}
task publishToS3(type: Exec, dependsOn: buildZip) {
onlyIf { file("${project.buildDir}/distributions").exist() }
def artifacts = new FileNameByRegexFinder().getFileNames("${project.buildDir}/distributions", /.*.zip/)
assert artifacts.size() == 1
def isSnapShot = artifacts[0].endsWith('-SNAPSHOT.zip')
def releaseCmd = ("aws s3 cp " +
"${artifacts[0]} " +
"s3://my-aws-lambdas/${project.name}/${isSnapShot ? 'SNAPSHOT' : 'release'}/ ").trim().tokenize(' ') as List
workingDir "${project.buildDir}/distributions"
commandLine releaseCmd
}
build.dependsOn buildZip
如果您在UNIX环境中,可以使用find
命令搜索文件并使用其输出。
task scanFiles() {
def a= "find ${project.buildDir} -name *.zip".execute().text
String[] files=a.split('n')
if(files.length == 1){
println("We'v got a file :"+a)
}
else if(files.length ==0){
println("We've not no files ")
}
else{
println("We've got multiple filesn"+a)
}
}