Java “运行”;npm安装“+;通过Maven为Node.js项目测试脚本

Java “运行”;npm安装“+;通过Maven为Node.js项目测试脚本,java,bash,shell,maven,jenkins,Java,Bash,Shell,Maven,Jenkins,作为Jenkins构建的一部分,Jenkins使用Maven,Maven反过来在项目的根目录下使用pom.xml文件。现在,这几乎是一个无操作: <project> <modelVersion>4.0.0</modelVersion> <groupId>com.dqsalpha-dev.app</groupId> <artifactId>dqsalpha</artifactId>

作为Jenkins构建的一部分,Jenkins使用Maven,Maven反过来在项目的根目录下使用pom.xml文件。现在,这几乎是一个无操作:

<project>
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.dqsalpha-dev.app</groupId>
    <artifactId>dqsalpha</artifactId>
    <version>1</version>
</project>
但这完全不正确。我只是意识到我可能还需要安装Node.js依赖项,使用npm安装

我试过这个:

然后我的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>

您可以使用exec maven插件:

<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>

execmaven插件
org.codehaus.mojo
测试1
包裹
执行官
${basedir}/test.sh
我只是意识到我可能还需要安装Node.js依赖项,使用npm安装

如果您在
test.sh
中所做的是Node.js和npm之类的东西,那么您可以改为使用Node.js和npm,尽管它的名称不同,它的设计目的是安装和运行Node.js和npm。这里有一个例子,但请参阅以获得更好的信息

<plugin>
  <groupId>com.github.eirslett</groupId>
  <artifactId>frontend-maven-plugin</artifactId>
  <version>1.9.1</version>

  <configuration>
    <nodeVersion>v12.16.0</nodeVersion>
  </configuration>

  <executions>
    <execution>
      <id>Install Node.js and npm</id>
      <goals>
        <goal>install-node-and-npm</goal>
      </goals>
    </execution>

    <execution>
      <id>npm install</id>
      <goals>
        <goal>npm</goal>
      </goals>
      <configuration>
        <workingDirectory>${your.npm.script.directory}</workingDirectory>
        <arguments>install</arguments>
      </configuration>
    </execution>
  </executions>
</plugin>

com.github.eirslett
前端maven插件
1.9.1
v12.16.0
安装Node.js和npm
安装节点和npm
npm安装
npm
${your.npm.script.directory}
安装
<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>
<plugin>
  <groupId>com.github.eirslett</groupId>
  <artifactId>frontend-maven-plugin</artifactId>
  <version>1.9.1</version>

  <configuration>
    <nodeVersion>v12.16.0</nodeVersion>
  </configuration>

  <executions>
    <execution>
      <id>Install Node.js and npm</id>
      <goals>
        <goal>install-node-and-npm</goal>
      </goals>
    </execution>

    <execution>
      <id>npm install</id>
      <goals>
        <goal>npm</goal>
      </goals>
      <configuration>
        <workingDirectory>${your.npm.script.directory}</workingDirectory>
        <arguments>install</arguments>
      </configuration>
    </execution>
  </executions>
</plugin>