# Travis CI env vars not being used in regression tests

**URL:** <https://travis-ci.community/t/travis-ci-env-vars-not-being-used-in-regression-tests/14553>\
**Category:** Deployment\
**Tags:** build-env, bug\
**Created:** [February 18, 2025, 8:17pm UTC](https://travis-ci.community/t/travis-ci-env-vars-not-being-used-in-regression-tests/14553 "2025-02-18T20:17:21Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mearsheimer](https://sea1.discourse-cdn.com/flex015/user_avatar/travis-ci.community/mearsheimer/32/9077_2.png) [@Mearsheimer](https://travis-ci.community/u/Mearsheimer)\
**Post date:** [February 18, 2025, 8:17pm UTC](https://travis-ci.community/t/travis-ci-env-vars-not-being-used-in-regression-tests/14553/1 "2025-02-18T20:17:21Z")

</div>

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:

```auto
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

---

<div class="post-metadata">

**Author:** ![Montana](https://sea1.discourse-cdn.com/flex015/user_avatar/travis-ci.community/montana/32/9566_2.png) [@Montana](https://travis-ci.community/u/Montana)\
**Post date:** [February 18, 2025, 8:19pm UTC](https://travis-ci.community/t/travis-ci-env-vars-not-being-used-in-regression-tests/14553/2 "2025-02-18T20:19:40Z")

</div>

Hi @Mearsheimer,

You should try adding a debug step in `.travis.yml`:

```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`:

```yml
env:
  global:
    - HITRAN_USERNAME=your_username
    - HITRAN_PASSWORD=your_password

```

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:

```python
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.")

```

This should solve the issue.

---

<div class="post-metadata">

**Author:** ![Mearsheimer](https://sea1.discourse-cdn.com/flex015/user_avatar/travis-ci.community/mearsheimer/32/9077_2.png) [@Mearsheimer](https://travis-ci.community/u/Mearsheimer)\
**Post date:** [February 18, 2025, 8:25pm UTC](https://travis-ci.community/t/travis-ci-env-vars-not-being-used-in-regression-tests/14553/3 "2025-02-18T20:25:22Z")

</div>

@montana,

seems like its building now

---

<div class="post-metadata">

**Author:** ![Montana](https://sea1.discourse-cdn.com/flex015/user_avatar/travis-ci.community/montana/32/9566_2.png) [@Montana](https://travis-ci.community/u/Montana)\
**Post date:** [February 18, 2025, 8:27pm UTC](https://travis-ci.community/t/travis-ci-env-vars-not-being-used-in-regression-tests/14553/4 "2025-02-18T20:27:03Z")

</div>

@Mearsheimer,

I’m glad I could help you solve the problem.
