What happens if you get stuck at a interactive prompt in build?
So you just made a really cool program in Python, or the language that you like, and you happen to be using the best CI/CD provider out there right now. (Travis CI). Now it comes to you, Python is asking the conditional you added, “Do you want to generate another name?” - your build is stuck and ends up timing out. Don’t worry, let me help you get out of this jam, and we’ll get out of it together.
Let’s get started
In some builds you’ll sometimes you come across
interactive prompts, this is usually asking if you want to upgrade packages, or if it’s something you made in Python say a ‘name generator’, and after it executes, it will ask “Generate another name?” - This would hold the build, and stop it from building - in turn causing the build to fail. In some cases you can use
expect to hop over this, but sometimes that doesn’t always work. In my years and years of using Travis I’ve always had a special way of doing this, and it’s really simple. I use a
So let’s say your program is called
namegen.py and you have it in a file called
./src, and the outcome of this after it’s executed is ‘Would you like another name generated? Y/N?’, it’s now stuck, now what?! Well don’t panic. So we know Python is looking for the inputs
N, so you’re not going to want Python to generate anymore names, so let’s make a
.txt file and entitle it
answer.txt (it can be called anything) and add it to our
.travis.yml. This is how the
script hook would look and how you tell Travis to call
script: python3 ./src/namegen.py < answer.txt
Now rerun your build, and it will hopefully be successful, and don’t feel bad if you’ve ran into this problem, we all have!