如果python脚本遇到任何错误,如何使Maven构建失败

问题描述 投票:0回答:1

我正在maven项目中使用python脚本,并且如果python脚本出现任何错误,希望通过正确的错误消息构建失败。

插件中是否有东西。从那里我们可能会失败构建并显示记录错误,如果python出现错误

这是我的pom.xml

<build>
    <plugins>
        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>exec-maven-plugin</artifactId>
            <version>1.6.0</version>
            <executions>
                <execution>
                    <configuration>
                        <executable>python</executable>
                        <workingDirectory>src/main/resources/</workingDirectory>
                        <arguments>
                            <argument>my.py</argument>
                        </arguments>
                    </configuration>
                    <id>python_build</id>
                    <phase>generate-resources</phase>
                    <goals>
                        <goal>exec</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

这是我的python脚本my.py

import logging

name = "Amit"
age = 24
if name != "Amit":
    logging.error("name is not matching")

if age != 24:
    logging.error("age is not matching")
java python maven-2 maven-3
1个回答
0
投票

如果要引发错误,请添加exit

import logging

name = "Amit"
age = 24
if name != "Amit":
    logging.error("name is not matching")
    exit(1)

if age != 24:
    logging.error("age is not matching")
    exit(1)
© www.soinside.com 2019 - 2024. All rights reserved.