2016-11-07 68 views
1

我目前正試圖在我們的Jenkins服務器上集成maven grunt jasmine。 期望的結果是,當我們運行構建(在配置中,我們將運行mvn clean install -Pgrunt),然後jenkins作業運行所有前端茉莉花測試。jenkins上的maven grunt 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']); 

}; 

而且我有一個在組件/ **/spec文件夾下的虛擬測試,假設它是dummytest.js:

describe("A suite", function() { 
    it("contains spec with an expectation", function() { 
    expect(true).toBe(true); 
    }); 
}); 

當我在本地運行,MVN全新安裝-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] ------------------------------------------------------------------------ 

但是,當我做的工作建立在基於完全相同詹金斯相同的代碼和配置,就成了:

[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 

這裏是我的詹金斯配置: enter image description here

正如你所看到的,我試圖測試,如果我的節點NPM和咕嚕正確安裝,這裏的輸出信息:

+ cd app 
+ pwd 
/data/apps/jenkins/workspace/maven-grunt-jasmine-testrun/app 
+ npm install 
npm WARN [email protected] No description 
npm WARN [email protected] No repository field. 
npm WARN [email protected] No license field. 
+ grunt --help 
/tmp/hudson5273188301428948376.sh: line 2: grunt: command not found 
Build step 'Execute shell' marked build as failure 
Finished: FAILURE 

所以我只是想知道,有什麼專家經歷過這種配置安裝程序之前?任何提示或建議都會很棒。 感謝

回答

0

經過研究,我發現它實際上是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> 

所以,在詹金斯,運行mvn clean install -Pinstall-node安裝NPM 然後,MVN乾淨的測試-Pgrunt - 詹金斯,
如果萬一失敗,運行mvn clean test -Premove-node-module刪除過期的node_modules 最後再次運行mvn clean test -Pgrunt-jenkins它爲我構建了一個成功的解決方案。謝謝

1

我不慎碰到這個問題這麼早,有機會的輔助腳本會幫助你: https://github.com/eirslett/frontend-maven-plugin#helper-scripts

乾杯。

+0

不是直接粘貼鏈接,而是將用戶帶走,如果您先在這裏詳細說明答案,然後再提供鏈接的任何額外詳細信息,那將會更好。 –

+0

你是對的我只是不知道如何評論這個問題。無論如何,有你downvote按鈕和upvote按鈕的答案。 我想。 –