I have set up my credentials (username/password) as environment variables in Travis CI. In my code, I am using the following snippet to retrieve these environment variables:
username = os.environ.get("HITRAN_USERNAME") or input("Enter HITRAN username: ")password = os.environ.get("HITRAN_PASSWORD") or getpass("Enter HITRAN password: ")
However, my tests are still prompting for credential input. How can I ensure that Travis CI correctly uses the environment variables? What might I be doing wrong?
I tried pulling env variables in the test, that didnt work aswell
You should try adding a debug step in .travis.yml:
before_script:
- echo "HITRAN_USERNAME is set to: $HITRAN_USERNAME"
If this prints an empty string, then the variables are not available. My second option to you is manually inject the environment variables in your .travis.yml:
However, do not hardcode secrets in the .travis.yml file. Instead, prefer the Travis UI settings.
As it pertains to your snippet of Python, from what I read of it - it’s not passing the variables really effectively. You’d have more success by doing something like:
import os
username = os.getenv("HITRAN_USERNAME")
password = os.getenv("HITRAN_PASSWORD")
if not username or not password:
raise ValueError("HITRAN credentials are missing from environment variables.")