Jenkins with pylint gives build failure

后端 未结 8 1023
天命终不由人
天命终不由人 2021-01-04 12:25

I added a build step to execute a Python script.
In this script pylint is called with the lint.Run(..args) to check the code.
The script works but in the end, the bu

相关标签:
8条回答
  • 2021-01-04 13:01

    Pylint has the unpleasant behavior to return a non-zero exit code even only if a small warning issue was found. Only when everything was fine, 0 is returned (see man page).

    As usually a non-zero code denotes an error, Jenkins fails the build.

    I see two ways to overcome this:

    • Use a small script around pylint that always returns 0. Then jenkins will not fail because of pylint. I use a small python script calling pylint with os.system() and sys.exit(0) after than. You can see it as overriding the error code of pylint.
    • Patch pylint. For example, on my Linux system the sys.exit() call is in the file /usr/lib/pymodules/python2.6/pylint/lint.py
    0 讨论(0)
  • 2021-01-04 13:02

    Ran into this today (although not using Jenkins).

    In my case it was because of how Pylint encodes fatal-error-warning-refactor-convention-usage info in its exit code: https://docs.pylint.org/en/1.6.0/run.html#exit-codes

    My fix:

    #!/usr/bin/env sh
    
    # Wraps Pylint invocation to produce shell-friendly exit codes
    # Because Pylint exit codes are weird:
    # https://docs.pylint.org/en/1.6.0/run.html#exit-codes
    
    PYTHON_EXECUTABLE=python
    if [ ! -z $PYTHON_ENV ]; then
        PYTHON_EXECUTABLE="$PYTHON_ENV/bin/python"
    fi
    
    ${PYTHON_EXECUTABLE} -m pylint $@
    
    PYLINT_EXIT_CODE=$?
    
    exit $(($PYLINT_EXIT_CODE % 4))
    

    (Gist: https://gist.github.com/nkashy1/ae59d06d4bf81fb72047fcd390d08903)

    0 讨论(0)
提交回复
热议问题