jenkins上的maven grunt jasmine前端测试集成
maven grunt jasmine front-end test integration on jenkins
我目前正在尝试在我们的 Jenkins 服务器上集成 maven g运行t jasmine。
预期的结果是,当我们 运行 构建时(在配置中我们将 运行 mvn clean install -Pg运行t)然后 jenkins 作业 运行s 所有前端茉莉花测试。
这是我的项目pom.xml
<profiles>
<profile>
<id>install-node</id>
<build>
<plugins>
<plugin>
<groupId>com.github.eirslett</groupId>
<artifactId>frontend-maven-plugin</artifactId>
<version>1.1</version>
<executions>
<execution>
<id>install node and npm</id>
<phase>generate-resources</phase>
<goals>
<goal>install-node-and-npm</goal>
</goals>
</execution>
<execution>
<id>npm install</id>
<phase>generate-resources</phase>
<goals>
<goal>npm</goal>
</goals>
<configuration>
<arguments>install</arguments>
</configuration>
</execution>
</executions>
<configuration>
<nodeVersion>v4.6.1</nodeVersion>
<npmVersion>2.15.9</npmVersion>
</configuration>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>grunt</id>
<build>
<plugins>
<plugin>
<groupId>com.github.eirslett</groupId>
<artifactId>frontend-maven-plugin</artifactId>
<version>1.1</version>
<executions>
<execution>
<id>grunt build</id>
<phase>generate-resources</phase>
<goals>
<goal>grunt</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
pom 旁边是我的 package.json
{
"name":"frontend-tools",
"version":"0.0.1",
"dependencies": {
"grunt": "~0.4.5",
"grunt-cli": "~0.1.13",
"grunt-contrib-jshint":"~0.10.0",
"grunt-contrib-jasmine":"~1.0.3"
},
"devDependencies": {}
}
和Gruntfile.js
module.exports = function(grunt) {
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.initConfig({
jasmine: {
customTemplate: {
src: 'jcr_root/apps/example/components/**/*.js',
options: {
specs: 'jcr_root/apps/example/components/**/spec/*.js',
helpers: 'jcr_root/apps/example/components/**/spec/*Helper.js',
vendor: [
"jcr_root/etc/designs/example/clientlibs_tools/js/jquery.js"
]
}
}
}
});
grunt.loadNpmTasks('grunt-contrib-jasmine');
grunt.registerTask('default', ['jasmine']);
};
我在 component/**/spec 文件夹下的某个地方有一个虚拟测试,假设它是一个 dummytest.js :
describe("A suite", function() {
it("contains spec with an expectation", function() {
expect(true).toBe(true);
});
});
当我在本地 运行ning 时一切正常,mvn clean install -Pg运行t
它给了我这样的预期效果:
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ app ---
[INFO] Deleting Z:\CQ5\example\app\target
[INFO]
[INFO] --- frontend-maven-plugin:1.1:grunt (grunt build) @ app ---
[INFO] Running 'grunt ' in Z:\CQ5\example\app
[INFO] Running "jasmine:customTemplate" (jasmine) task
[INFO] A suite
[INFO] - contains spec with an expectation......â??
[INFO] A suite is just a function
[INFO] - and so is a spec......â??
[INFO] 4 specs in 0.002s.
[INFO] >> 0 failures
[INFO]
[INFO] Done, without errors.
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
但是当我基于完全相同的代码和配置在 jenkins 上构建作业时,它变成了:
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ app ---
[INFO]
[INFO] --- frontend-maven-plugin:1.1:grunt (grunt build) @ app ---
[INFO] Running 'grunt ' in /data/apps/jenkins/workspace/maven-grunt-jasmine-testrun/app
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 3.627 s
[INFO] Finished at: 2016-11-07T11:26:39+00:00
[INFO] Final Memory: 20M/218M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal com.github.eirslett:frontend-maven-plugin:1.1:grunt (grunt build) on project app: Failed to run task: 'grunt ' failed. java.io.IOException: Cannot run program "/data/apps/jenkins/workspace/maven-grunt-jasmine-testrun/app/node/node" (in directory "/data/apps/jenkins/workspace/maven-grunt-jasmine-testrun/app"): error=2, No such file or directory -> [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/MojoFailureException
Waiting for Jenkins to finish collecting data
这是我的詹金斯配置:
如您所见,我正在尝试测试我的节点 npm 和 g运行t 是否安装正确,这里是输出信息:
+ cd app
+ pwd
/data/apps/jenkins/workspace/maven-grunt-jasmine-testrun/app
+ npm install
npm WARN frontend-tools@0.0.1 No description
npm WARN frontend-tools@0.0.1 No repository field.
npm WARN frontend-tools@0.0.1 No license field.
+ grunt --help
/tmp/hudson5273188301428948376.sh: line 2: grunt: command not found
Build step 'Execute shell' marked build as failure
Finished: FAILURE
所以我想知道,有没有专家以前经历过这种配置设置?任何提示或建议都会很棒。
谢谢
经过研究,我发现实际上是 node_modules 文件夹已过时,所以我创建了另一个配置文件只是为了删除 jenkins 上的 node_modules。
这是更新后的 pom.xml 个配置文件:
<profiles>
<profile>
<id>install-node</id>
<build>
<plugins>
<plugin>
<groupId>com.github.eirslett</groupId>
<artifactId>frontend-maven-plugin</artifactId>
<version>1.1</version>
<executions>
<execution>
<id>install node and npm</id>
<phase>generate-resources</phase>
<goals>
<goal>install-node-and-npm</goal>
</goals>
</execution>
<execution>
<id>npm install</id>
<phase>generate-resources</phase>
<goals>
<goal>npm</goal>
</goals>
<configuration>
<arguments>install</arguments>
</configuration>
</execution>
</executions>
<configuration>
<nodeVersion>v4.6.1</nodeVersion>
<npmVersion>2.15.9</npmVersion>
</configuration>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>remove-node-module</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-clean-plugin</artifactId>
<version>2.4.1</version>
<configuration>
<followSymLinks>false</followSymLinks>
<filesets>
<fileset>
<directory>${basedir}/node_modules</directory>
</fileset>
</filesets>
</configuration>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>grunt-jenkins</id>
<build>
<plugins>
<plugin>
<groupId>com.github.eirslett</groupId>
<artifactId>frontend-maven-plugin</artifactId>
<version>1.1</version>
<executions>
<execution>
<id>grunt jenkins</id>
<phase>generate-resources</phase>
<goals>
<goal>grunt</goal>
</goals>
<configuration>
<arguments>jenkins</arguments>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
所以,在 jenkins 上,运行 mvn clean install -Pinstall-node
安装 npm
然后, mvn clean test -Pg运行t-jenkins,
如果万一失败,运行 mvn clean test -Premove-node-module
删除过时的 node_modules
终于再次 运行 mvn clean test -Pgrunt-jenkins
它为我成功构建。谢谢
我目前正在尝试在我们的 Jenkins 服务器上集成 maven g运行t jasmine。 预期的结果是,当我们 运行 构建时(在配置中我们将 运行 mvn clean install -Pg运行t)然后 jenkins 作业 运行s 所有前端茉莉花测试。
这是我的项目pom.xml
<profiles>
<profile>
<id>install-node</id>
<build>
<plugins>
<plugin>
<groupId>com.github.eirslett</groupId>
<artifactId>frontend-maven-plugin</artifactId>
<version>1.1</version>
<executions>
<execution>
<id>install node and npm</id>
<phase>generate-resources</phase>
<goals>
<goal>install-node-and-npm</goal>
</goals>
</execution>
<execution>
<id>npm install</id>
<phase>generate-resources</phase>
<goals>
<goal>npm</goal>
</goals>
<configuration>
<arguments>install</arguments>
</configuration>
</execution>
</executions>
<configuration>
<nodeVersion>v4.6.1</nodeVersion>
<npmVersion>2.15.9</npmVersion>
</configuration>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>grunt</id>
<build>
<plugins>
<plugin>
<groupId>com.github.eirslett</groupId>
<artifactId>frontend-maven-plugin</artifactId>
<version>1.1</version>
<executions>
<execution>
<id>grunt build</id>
<phase>generate-resources</phase>
<goals>
<goal>grunt</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
pom 旁边是我的 package.json
{
"name":"frontend-tools",
"version":"0.0.1",
"dependencies": {
"grunt": "~0.4.5",
"grunt-cli": "~0.1.13",
"grunt-contrib-jshint":"~0.10.0",
"grunt-contrib-jasmine":"~1.0.3"
},
"devDependencies": {}
}
和Gruntfile.js
module.exports = function(grunt) {
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.initConfig({
jasmine: {
customTemplate: {
src: 'jcr_root/apps/example/components/**/*.js',
options: {
specs: 'jcr_root/apps/example/components/**/spec/*.js',
helpers: 'jcr_root/apps/example/components/**/spec/*Helper.js',
vendor: [
"jcr_root/etc/designs/example/clientlibs_tools/js/jquery.js"
]
}
}
}
});
grunt.loadNpmTasks('grunt-contrib-jasmine');
grunt.registerTask('default', ['jasmine']);
};
我在 component/**/spec 文件夹下的某个地方有一个虚拟测试,假设它是一个 dummytest.js :
describe("A suite", function() {
it("contains spec with an expectation", function() {
expect(true).toBe(true);
});
});
当我在本地 运行ning 时一切正常,mvn clean install -Pg运行t 它给了我这样的预期效果:
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ app ---
[INFO] Deleting Z:\CQ5\example\app\target
[INFO]
[INFO] --- frontend-maven-plugin:1.1:grunt (grunt build) @ app ---
[INFO] Running 'grunt ' in Z:\CQ5\example\app
[INFO] Running "jasmine:customTemplate" (jasmine) task
[INFO] A suite
[INFO] - contains spec with an expectation......â??
[INFO] A suite is just a function
[INFO] - and so is a spec......â??
[INFO] 4 specs in 0.002s.
[INFO] >> 0 failures
[INFO]
[INFO] Done, without errors.
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
但是当我基于完全相同的代码和配置在 jenkins 上构建作业时,它变成了:
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ app ---
[INFO]
[INFO] --- frontend-maven-plugin:1.1:grunt (grunt build) @ app ---
[INFO] Running 'grunt ' in /data/apps/jenkins/workspace/maven-grunt-jasmine-testrun/app
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 3.627 s
[INFO] Finished at: 2016-11-07T11:26:39+00:00
[INFO] Final Memory: 20M/218M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal com.github.eirslett:frontend-maven-plugin:1.1:grunt (grunt build) on project app: Failed to run task: 'grunt ' failed. java.io.IOException: Cannot run program "/data/apps/jenkins/workspace/maven-grunt-jasmine-testrun/app/node/node" (in directory "/data/apps/jenkins/workspace/maven-grunt-jasmine-testrun/app"): error=2, No such file or directory -> [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/MojoFailureException
Waiting for Jenkins to finish collecting data
这是我的詹金斯配置:
如您所见,我正在尝试测试我的节点 npm 和 g运行t 是否安装正确,这里是输出信息:
+ cd app
+ pwd
/data/apps/jenkins/workspace/maven-grunt-jasmine-testrun/app
+ npm install
npm WARN frontend-tools@0.0.1 No description
npm WARN frontend-tools@0.0.1 No repository field.
npm WARN frontend-tools@0.0.1 No license field.
+ grunt --help
/tmp/hudson5273188301428948376.sh: line 2: grunt: command not found
Build step 'Execute shell' marked build as failure
Finished: FAILURE
所以我想知道,有没有专家以前经历过这种配置设置?任何提示或建议都会很棒。 谢谢
经过研究,我发现实际上是 node_modules 文件夹已过时,所以我创建了另一个配置文件只是为了删除 jenkins 上的 node_modules。
这是更新后的 pom.xml 个配置文件:
<profiles>
<profile>
<id>install-node</id>
<build>
<plugins>
<plugin>
<groupId>com.github.eirslett</groupId>
<artifactId>frontend-maven-plugin</artifactId>
<version>1.1</version>
<executions>
<execution>
<id>install node and npm</id>
<phase>generate-resources</phase>
<goals>
<goal>install-node-and-npm</goal>
</goals>
</execution>
<execution>
<id>npm install</id>
<phase>generate-resources</phase>
<goals>
<goal>npm</goal>
</goals>
<configuration>
<arguments>install</arguments>
</configuration>
</execution>
</executions>
<configuration>
<nodeVersion>v4.6.1</nodeVersion>
<npmVersion>2.15.9</npmVersion>
</configuration>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>remove-node-module</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-clean-plugin</artifactId>
<version>2.4.1</version>
<configuration>
<followSymLinks>false</followSymLinks>
<filesets>
<fileset>
<directory>${basedir}/node_modules</directory>
</fileset>
</filesets>
</configuration>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>grunt-jenkins</id>
<build>
<plugins>
<plugin>
<groupId>com.github.eirslett</groupId>
<artifactId>frontend-maven-plugin</artifactId>
<version>1.1</version>
<executions>
<execution>
<id>grunt jenkins</id>
<phase>generate-resources</phase>
<goals>
<goal>grunt</goal>
</goals>
<configuration>
<arguments>jenkins</arguments>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
所以,在 jenkins 上,运行 mvn clean install -Pinstall-node
安装 npm
然后, mvn clean test -Pg运行t-jenkins,
如果万一失败,运行 mvn clean test -Premove-node-module
删除过时的 node_modules
终于再次 运行 mvn clean test -Pgrunt-jenkins
它为我成功构建。谢谢