詹金斯构建错误 Maven Angular2
Posted
技术标签:
【中文标题】詹金斯构建错误 Maven Angular2【英文标题】:Jenkins Build Error Maven Angular2 【发布时间】:2018-04-08 01:28:47 【问题描述】:当我尝试自动安装和构建 Angular 2 应用程序时出现以下错误。该应用程序在 GIT 上,那部分很好。我达到了第二个目标,我可以很好地安装 nodeModules,但是在试图将 angular 应用程序构建到 dist 文件夹的第二步中它失败了。我基本上希望它在 maven 中执行相当于 ng build --environment=sys 的操作。
[ERROR] Failed to execute goal org.codehaus.mojo:exec-maven-plugin:1.4.0:exec (ng build) on project consumer-dashboard: Command execution failed. Cannot run program "ng" (in directory "D:\Jenkins\PFS Jobs\consumer-dashboard\workspace\consumer-dashboard\src"): CreateProcess error=2, The system cannot find the file specified -> [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:
[JENKINS] Archiving D:\Jenkins\PFS Jobs\consumer-dashboard\workspace\consumer-dashboard\pom.xml to consumer-dashboard/consumer-dashboard/1.0.0-SNAPSHOT/consumer-dashboard-1.0.0-SNAPSHOT.pom
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
channel stopped
使用 Jenkins 在构建服务器上的 pom 中运行它;
<build>
<plugins>
<plugin>
<artifactId>exec-maven-plugin</artifactId>
<groupId>org.codehaus.mojo</groupId>
<version>1.4.0</version>
<executions>
<execution>
<id>npm install</id>
<goals>
<goal>exec</goal>
</goals>
<phase>generate-sources</phase>
<configuration>
<executable>npm</executable>
<arguments>
<argument>install</argument>
<argument>-g angular-cli</argument>
</arguments>
<workingDirectory>./src</workingDirectory>
<target>
<echo message="npm install" />
</target>
</configuration>
</execution>
<execution>
<id>ng build</id>
<goals>
<goal>exec</goal>
</goals>
<phase>generate-sources</phase>
<configuration>
<executable>ng</executable>
<arguments>
<argument>build</argument>
<argument>--environment=sys</argument>
</arguments>
<workingDirectory>./src</workingDirectory>
<target>
<echo message="ng build" />
</target>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
不知道为什么找不到ng?
【问题讨论】:
我会重新考虑使用 Maven 来构建 Angular 应用程序... 您认为哪种方式效果更好? 用ng build...
怎么样?
感谢 khmarbaise,npm build 是前进的方向,请参阅下文
我不会将 Maven 用于此类应用程序...仅ng build...
...
【参考方案1】:
我通过以下操作解决了这个问题;
<plugin>
<artifactId>exec-maven-plugin</artifactId>
<groupId>org.codehaus.mojo</groupId>
<version>1.4.0</version>
<executions>
<execution>
<id>npm install</id>
<goals>
<goal>exec</goal>
</goals>
<phase>generate-sources</phase>
<configuration>
<executable>npm</executable>
<arguments>
<argument>install</argument>
</arguments>
<workingDirectory>./</workingDirectory>
<target>
<echo message="npm install" />
</target>
</configuration>
</execution>
<execution>
<id>ng build</id>
<goals>
<goal>exec</goal>
</goals>
<phase>generate-sources</phase>
<configuration>
<executable>npm</executable>
<arguments>
<argument>run</argument>
<argument>build-sys</argument>
</arguments>
<workingDirectory>./</workingDirectory>
<target>
<echo message="ng build" />
</target>
</configuration>
</execution>
</executions>
</plugin>
并在 package.json 中添加“build-sys”;
"name": "project-name",
"version": "0.0.0",
"license": "MIT",
"scripts":
"ng": "ng",
"start": "ng serve",
"build": "ng build",
"build-sys": "ng build --environment=sys",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e"
通过这样做,我最终得到了一个包含正确环境属性的 dist。
感谢@khmarbaise 的建议!
【讨论】:
以上是关于詹金斯构建错误 Maven Angular2的主要内容,如果未能解决你的问题,请参考以下文章