【问题标题】:maven grunt jasmine front-end test integration on jenkinsjenkins 上的 maven grunt jasmine 前端测试集成
【发布时间】:2016-11-07 12:11:02
【问题描述】:

我目前正在尝试在我们的 Jenkins 服务器上集成 maven grunt jasmine。 预期的结果是,当我们运行构建(在配置中我们将运行 mvn clean install -Pgrunt)然后 jenkins 作业运行所有前端 jasmine 测试。

这是我的项目 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);
  });
});

当我在本地运行时,一切正常,mvn clean install -Pgrunt 它给了我这样的预期效果:

[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 和 grunt 是否安装正确,以下是输出信息:

+ 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

所以我只是想知道,以前有没有专家经历过这种配置设置?任何提示或建议都会很棒。 谢谢

【问题讨论】:

    标签: maven jenkins gruntjs jasmine aem


    【解决方案1】:

    经过研究,我发现它实际上是 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 -Pgrunt-jenkins,
    如果失败,请运行mvn clean test -Premove-node-module 删除过时的 node_modules 最后再次运行mvn clean test -Pgrunt-jenkins 它为我成功构建。谢谢

    【讨论】:

      猜你喜欢
      • 2013-12-16
      • 2014-04-25
      • 2014-03-12
      • 1970-01-01
      • 2016-03-19
      • 1970-01-01
      • 2012-03-15
      • 2016-10-27
      • 1970-01-01
      相关资源
      最近更新 更多