应用运行成功后,我的travis-ci构建将永远运行

时间:2019-02-10 18:35:49

标签: python-3.x travis-ci

我有一个小型的python应用程序,我想确保当有人提出新的github pull request / commit时,它能够顺利启动。

现在的问题是,一旦我运行该应用程序,它就会永远运行,因为一切正常,没有任何问题。

自构建2分钟后是否可以关闭状态为0的构建?

这是我的.travis.yml文件


python:
  - "3.7-dev"

install:
  - pip3 install -r requirements.txt
  - pip3 install pytest

before_script:
  - chmod +x deploy.sh
  - chmod +x changelog.sh



branches:
  only:
    - travis-test

script:
  - python3 -m tg_companion

after_success:
  ./deploy.sh

2 个答案:

答案 0 :(得分:1)

执行此操作的一种方法是将应用程序的开始包裹在脚本中,该脚本会在一定时间后终止。

travis.yml中设置:

script:
  - bash timeout.sh

然后创建一个timeout.sh脚本:

#!/bin/bash

# Run your app in the background
python3 -m tg_companion &

# Store it's Process ID
bg_pid=$!

# sleep for X seconds
sleep 120

# Kill the python process
kill $bg_pid

# Optionally exit true to prevent travis seeing this as an error
exit 0

另一种方法是修改模块以通知其在测试模式下运行的时间,并在超时(可能是命令行标志)或查看环境(例如)后终止自身。 TRAVIS=trueCI=true

答案 1 :(得分:0)

使用以下代码创建另一个python文件test.py。

import tg_companion

运行test代替运行tg_companion。即-python3 -m test (在.travis.yml脚本中)

相关问题