我正在尝试在shell脚本中执行maven构建。我在ec2实例中在Amazon Linux上运行。
以下是我脚本中的前两行:
sudo git clone [url of git repository]
sudo mvn clean package -f /path/to/pom.xml
如果我在命令行中单独输入它们,那么它可以工作。
如果我已经克隆了存储库然后执行脚本,那么它可以工作。它跳过克隆存储库(因为它已经存在)并继续执行脚本的其余部分。再次,这是有效的。
当repo不存在且我运行脚本时会出现问题。它克隆远程仓库并且看起来是成功的。
但是当它试图打包项目时我遇到了这个错误:
您可以看到克隆了repo,然后构建启动,但失败了。我甚至尝试在clone和mvn package命令之间等待5秒。
[ec2-user@ip-10-0-1-16 ~]$ build_script
Cloning into 'devops'...
remote: Counting objects: 649, done.
remote: Compressing objects: 100% (548/548), done.
remote: Total 649 (delta 314), reused 88 (delta 24)
Receiving objects: 100% (649/649), 18.96 MiB | 0 bytes/s, done.
Resolving deltas: 100% (314/314), done.
Checking connectivity... done.
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building UserRegistrationClient current
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ demo ---
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ demo ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.890 s
[INFO] Finished at: 2015-08-28T18:43:04+00:00
[INFO] Final Memory: 11M/26M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-resources-plugin:2.6:resources (default-resources) on project demo: Cannot create resource output directory: /home/ec2-user/devops/UserRegistrationClient/target/classes -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
答案 0 :(得分:1)
错误清楚地表明这是权限问题:
Cannot create resource output directory: /home/ec2-user/devops/UserRegistrationClient/target/classes
这与您的描述“The problem occurs when the repo isn't present and I run the script
”一致,因为当它不存在时,您使用sudo
创建它,因此它属于root
,而权限不会更改回购已经存在。
为了更好地了解实际情况,您应该在脚本中添加一些跟踪,特别是一些ls -l
,以便检查您操作的目录的所有者,以及一些whoami
为了看谁在执行某项行动