我正在gradle中创建部署脚本。我需要压缩我的应用程序,以便将其上传到s3并通过代码部署部署修订版。我可以手动运行zip -r Archive.zip *
来实现这一目标。但是当我尝试在gradle中运行相同的命令时出现错误,请参阅下面的调试日志。
任务:
task zip {
doLast {
exec {
workingDir '.'
commandLine 'zip', '-r', 'Archive.zip', '*'
}
}
}
日志:
13:01:24.961 [DEBUG] [org.gradle.process.internal.DefaultExecHandle] Changing state to: STARTING
13:01:24.961 [DEBUG] [org.gradle.process.internal.DefaultExecHandle] Waiting until process started: command 'zip'.
13:01:24.987 [DEBUG] [org.gradle.process.internal.DefaultExecHandle] Changing state to: STARTED
13:01:24.988 [DEBUG] [org.gradle.process.internal.ExecHandleRunner] waiting until streams are handled...
13:01:24.988 [INFO] [org.gradle.process.internal.DefaultExecHandle] Successfully started process 'command 'zip''
13:01:25.018 [QUIET] [system.out]
13:01:25.018 [QUIET] [system.out] zip error: Nothing to do! (try: zip -r Archive.zip . -i *)
13:01:25.019 [DEBUG] [org.gradle.process.internal.DefaultExecHandle] Changing state to: FAILED
13:01:25.019 [DEBUG] [org.gradle.process.internal.DefaultExecHandle] Process 'command 'zip'' finished with exit value 12 (state: FAILED)
13:01:25.019 [DEBUG] [org.gradle.internal.progress.DefaultBuildOperationExecutor] Completing Build operation 'Execute doLast {} action for :zip'
13:01:25.019 [DEBUG] [org.gradle.api.internal.tasks.execution.ResolveTaskArtifactStateTaskExecuter] Removed task artifact state for {} from context.
13:01:25.020 [DEBUG] [org.gradle.api.internal.tasks.execution.ExecuteAtMostOnceTaskExecuter] Finished executing task ':zip'
13:01:25.020 [DEBUG] [org.gradle.internal.progress.DefaultBuildOperationExecutor] Completing Build operation 'Task :zip'
13:01:25.020 [null] [org.gradle.internal.progress.DefaultBuildOperationExecutor]
13:01:25.020 [DEBUG] [org.gradle.internal.progress.DefaultBuildOperationExecutor] Build operation 'Task :zip' completed
13:01:25.020 [INFO] [org.gradle.execution.taskgraph.DefaultTaskPlanExecutor] :zip (Thread[Task worker for ':',5,main]) completed. Took 0.063 secs.
13:01:25.020 [DEBUG] [org.gradle.internal.work.DefaultWorkerLeaseService] Worker lease root.1.2 completed (1 worker(s) in use)
13:01:25.020 [DEBUG] [org.gradle.internal.resources.AbstractTrackedResourceLock] Task worker for ':': released lock on root.1.2
13:01:25.020 [DEBUG] [org.gradle.internal.resources.AbstractTrackedResourceLock] Task worker for ':': released lock on :
13:01:25.020 [DEBUG] [org.gradle.execution.taskgraph.DefaultTaskPlanExecutor] Task worker [Thread[Task worker for ':',5,main]] finished, busy: 0.063 secs, idle: 0.002 secs
12:56:42.933 [DEBUG] [org.gradle.internal.progress.DefaultBuildOperationExecutor] Completing Build operation 'Run tasks'
12:56:42.935 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter]
12:56:42.935 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] FAILURE: Build failed with an exception.
12:56:42.935 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter]
12:56:42.935 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] * Where:
12:56:42.935 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] Build file '/app/build.gradle' line: 50
12:56:42.935 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter]
12:56:42.935 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] * What went wrong:
12:56:42.935 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] Execution failed for task ':zip'.
12:56:42.935 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] > Process 'command 'zip'' finished with non-zero exit value 12
12:56:42.935 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter]
12:56:42.935 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] * Try:
12:56:42.935 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] Run with --stacktrace option to get the stack trace.
12:56:42.935 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter]
12:56:42.935 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] * Get more help at https://help.gradle.org
12:56:42.935 [ERROR] [org.gradle.internal.buildevents.BuildResultLogger]
12:56:42.935 [ERROR] [org.gradle.internal.buildevents.BuildResultLogger] BUILD FAILED in 0s
答案 0 :(得分:0)
在日志中有明确的消息打印到stdout:
13:01:25.018 [QUIET] [system.out] zip错误:无事可做! (试试:拉链 -r Archive.zip。 -i *)
您的命令无效。
此外..没有必要在gradle中手动运行zip。对此有一个预定义的task。
答案 1 :(得分:0)
以下任务解决了我的问题:
task zip {
doLast {
exec {
workingDir '.'
commandLine 'zip', '-r', 'Archive.zip', '.'
}
}
}