当我尝试自动安装和构建角度2应用程序时,获取以下错误。申请是在GIT上,那部分是好的。我得到第二个目标,我可以安装nodeModules,但它在第二步尝试将角度应用程序构建到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?
答案 0 :(得分:0)
我通过执行以下操作解决了这个问题;
<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的建议!