CJ Dennis
CJ Dennis

Reputation: 4336

Why does my secure Travis CI environment variable not work?

Every time I deploy to Github, Travis CI says at the end of its report:

Dashboard report has not been sent: neither INFECTION_BADGE_API_KEY nor STRYKER_DASHBOARD_API_KEY were found in the environment

I've tried setting the environment variable at least four times:

At first my .travis.yml file looked like this:

language: php

php:
  - '7.3'

install: composer update

script:
  - vendor/bin/infection --min-covered-msi=90 --min-msi=90

dd:
  secure: "A/s0...bS8="

This was because I had missed one of the dashes in the --add in travis encrypt STRYKER_DASHBOARD_API_KEY=<my-secret-uuid-key> --add (from step 4 in the link).

When I fixed that it gave the same error message:

-dd:
-  secure: A/s0...bS8=
+env:
+  global:
+    secure: A/s0...bS8=

Each subsequent attempt gave the same error. Trying to generate a new key:

-    secure: A/s0...bS8=
+    - secure: iQra...Ol0=

Quoting the encrypted value:

-    - secure: iQra...Ol0=
+    - secure: 'iQra...Ol0='

Not using the --add option but manually copying from the console and pasting into the config file:

-    - secure: 'iQra...Ol0='
+    secure: "CPPE...3nk="

What's the right way to get this working?

Upvotes: 1

Views: 1460

Answers (1)

CJ Dennis
CJ Dennis

Reputation: 4336

TL;DR: new free Travis CI accounts are now created on the professional server.


Hard to diagnose, easy to fix! The instructions for creating a secure environment variable on Travis CI fail to mention that all new accounts are now created on the professional server (travis-ci.com), and no longer on the old free server (travis-ci.org), even the free accounts! What's even more confusing is that you can see the same account at both addresses!

So, to encrypt an environment variable, you must pass the server flag (--pro or --com) to travis encrypt:

travis encrypt --pro MY_SECRET_ENV=super_secret --add

or

travis encrypt --com MY_SECRET_ENV=super_secret --add

where you replace MY_SECRET_ENV with the name of your variable and super_secret with the actual value.

If you have an old free account that is still on travis-ci.org you can continue to use:

travis encrypt MY_SECRET_ENV=super_secret --add

or

travis encrypt --org MY_SECRET_ENV=super_secret --add

For travis encrypt to output values that can be successfully decrypted, you must know which server your account is on, which is currently very confusing for new users.

Upvotes: 6

Related Questions