0

I am using python script in maven project and want to fail build with proper error message if python script gets any error.

Is there something in plugin. from where we can fail build and display logging error if python gets error

this is my 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>

and here is my python script 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")

1 Answers1

0

Add exit if you want raise an error:

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)
Jens
  • 67,715
  • 15
  • 98
  • 113