Travis_terminate command not found

I am running a Python script during the before_deploy stage to determine the presence of a file. If that file is not found, I am trying to use the poorly-documented travis_terminate command to halt the process:

run_process(["travis_terminate", "0"])

This seems to be a common approach, as mentioned in #1574 and other issues. However, this invocation results in a FileNotFoundError:

FileNotFoundError: [Errno 2] No such file or directory: 'travis_terminate': 'travis_terminate'

At first, I thought the cause was that I had not opted-into the (deprecated) v0 conditions, but even after adding conditions: v0 to the top of .travis.yml, the result is the same error.

The equivalent command for CircleCI, by the way, functions flawlessly:

run_process(["circleci", "step", "halt"])

Why does calling travis_terminate result in a “file not found” error? Is it not available during the before_deploy stage? Or has the travis_terminate command been removed without warning? If so, what invocation can instead be used to immediately halt the process, with the ability to specify 0 or 1 exit codes?

travis_terminate is a shell function, defined in https://github.com/travis-ci/travis-build/blob/master/lib/travis/build/bash/travis_terminate.bash which is imported (in unspecified manner) into the shell that runs user commands and is designed to run in the same shell as them. As such, you cannot run it from a Python subprocess.

I suggest your Python program returns an exit code depending on which you’ll call travis_terminate:

before_deploy:
    - ./is_deploy_needed.py || travis_terminate 0
2 Likes

@native-api: Your guidance provided the clarity that was so sorely lacking. Many thanks for taking the time to respond and point me in the right direction. Much appreciated! :clap:

As a side note, I needed travis_terminate in order to support Travis CI in AutoPub, a tool that enables project maintainers to automate new package version releases upon pull request merge. Just thought I’d mention it in case AutoPub could be of use to somebody else. :sparkles:

1 Like
Imprint