Artandor
Artandor

Reputation: 480

Symfony insight env var not found for global twig variable

I'm running Symfony Insight with a gitlab CI in order to improve my code quality.

I recently added google recaptcha, which needs a public (used in twig) and a private token (used in controller).

To do a clean job, I added them both as environment variables, added the pub one as twig global variable, and i get the private one with getenv.

I a am now getting the "A Symfony application should be bootable" error on symfony insight, with the following stacktrace :

Symfony\Component\DependencyInjection\Exception\EnvNotFoundException: Environment variable not found: "RECAPTCHA_PUBLIC_KEY". in /home/foobar/code/vendor/symfony/dependency-injection/EnvVarProcessor.php:97

Note that everything is working properly on both local and php unit tests (also ran by CI)

I'm guessing that the insight isn't finding the env var when trying to initiate the global twig variable.

Here is my .env.dist file : (the keys are google testing key, not my real ones, don't worry)

###> google-recaptcha ###
RECAPTCHA_PRIVATE_KEY=6LeIxAcTAAAAAGG-vFI1TnRWxMZNFuojJ4WifJWe
RECAPTCHA_PUBLIC_KEY=6LeIxAcTAAAAAJcZVRqyHh71UMIEGNQ_MXjiZKhI
###< google-recaptcha ###

Here is my twig variable declaration :

globals:
    recaptcha_public_key: '%env(RECAPTCHA_PUBLIC_KEY)%'

And my gitlab-ci insight config:

insight:
    stage: insight
    image: php:7.1
    tags:
        - symfony4
    script:
        - curl -o insight.phar -s https://get.insight.symfony.com/insight.phar
        - php insight.phar analyze --no-interaction --no-ansi cc8f0c98-ce1b-4b1e-acc4-9dfafd4bafc4 -v --reference=$CI_COMMIT_SHA --user-uuid=23888e4d-ec4f-479b-90c6-ee454c7bfc88 --api-token=b1dcbef05392e237a5ee5d29ea348b9ab7179245b0f086c3490478b0ae643272 --fail-condition="counts.critical > 0 or counts.major > 0"
    only:
        - develop
        - master
variables:
    MYSQL_DATABASE: higalsymf
    DATABASE_HOST: mysql
    MYSQL_ROOT_PASSWORD: root

Upvotes: 2

Views: 1699

Answers (1)

Mikołaj
Mikołaj

Reputation: 59

The first idea: you can insert tokens in variables section in gitlab-ci.yml.

Second idea is add command cp .env.dist .env in section before_script in gitlab-ci.yml.

Upvotes: 0

Related Questions