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

How to fail maven build if python script get any error

我在 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")

如果要引发错误,请添加 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)