2017-04-11 49 views
0

作爲Jenkins構建的一部分,Jenkins使用Maven,Maven在我們的項目的根目錄中使用了pom.xml文件。現在,這幾乎是一個無操作:通過Maven for Node.js項目運行「npm install」+測試腳本

<project> 
    <modelVersion>4.0.0</modelVersion> 
    <groupId>com.dqsalpha-dev.app</groupId> 
    <artifactId>dqsalpha</artifactId> 
    <version>1</version> 
</project> 

我想一件事情到這個POM文件 - 我要當運行maven build運行測試(它只是一個shell腳本)。

通過pom文件添加測試到Maven構建的最簡單方法是什麼?

事情是這樣的:

<project> 
     <modelVersion>4.0.0</modelVersion> 
     <groupId>com.dqsalpha-dev.app</groupId> 
     <artifactId>dqsalpha</artifactId> 
     <version>1</version> 
     <test> 
      <bash> 
      @test.sh 
      </bash> 
     </test> 
    </project> 

除了是完全不正確的。我只是意識到我也可能需要安裝Node.js依賴關係,以及npm install。

我嘗試這樣做:

https://bitbucket.org/atlassian/bash-maven-plugin

然後我的pom.xml的樣子:

<project> 
    <modelVersion>4.0.0</modelVersion> 
    <groupId>com.dqsalpha-dev.app</groupId> 
    <artifactId>dqsalpha</artifactId> 
    <version>1</version> 
    <build> 
     <plugins> 
      <plugin> 

       <groupId>com.atlassian.maven.plugins</groupId> 
       <artifactId>bash-maven-plugin</artifactId> 
       <version>1.0-SNAPSHOT</version> 
       <executions> 
        <execution> 
         <id>test</id> 
         <phase>integration-test</phase> 
         <goals> 
          <goal>run</goal> 
         </goals> 
        </execution> 
       </executions> 
       <configuration> 
        <script> 
         npm install; 
         ./test.sh 
        </script> 
       </configuration> 
      </plugin> 
     </plugins> 
    </build> 
    <properties> 
     <example.one>Variable replacement is available from Maven.</example.one> 
    </properties> 
    <dependencies> 
     <dependency> 
      <groupId>com.atlassian.maven.plugins</groupId> 
      <artifactId>bash-maven-plugin</artifactId> 
      <version>1.0-SNAPSHOT</version> 
      <scope>provided</scope> 
     </dependency> 
    </dependencies> 
</project> 

但後來我得到這個錯誤:

$ mvn clean install 
[INFO] Scanning for projects... 
[INFO]                   
[INFO] ------------------------------------------------------------------------ 
[INFO] Building dqsalpha 1 
[INFO] ------------------------------------------------------------------------ 
[WARNING] The POM for com.atlassian.maven.plugins:bash-maven-plugin:jar:1.0-SNAPSHOT is missing, no dependency information available 
[INFO] ------------------------------------------------------------------------ 
[INFO] BUILD FAILURE 
[INFO] ------------------------------------------------------------------------ 
[INFO] Total time: 0.187 s 
[INFO] Finished at: 2017-04-11T16:09:24-07:00 
[INFO] Final Memory: 8M/309M 
[INFO] ------------------------------------------------------------------------ 
[ERROR] Plugin com.atlassian.maven.plugins:bash-maven-plugin:1.0-SNAPSHOT or one of its dependencies could not be resolved: Could not find artifact com.atlassian.maven.plugins:bash-maven-plugin:jar:1.0-SNAPSHOT -> [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/PluginResolutionException 

回答

0

您可以使用exec-maven-plugin

<plugin> 
    <artifactId>exec-maven-plugin</artifactId> 
    <groupId>org.codehaus.mojo</groupId> 
    <executions> 
     <execution> 
      <id>test1</id> 
      <phase>package</phase> 
      <goals> 
       <goal>exec</goal> 
      </goals> 
      <configuration> 
       <executable>${basedir}/test.sh</executable> 
      </configuration> 
     </execution> 
    </executions> 
</plugin> 
相關問題