AzJa
AzJa

Reputation: 121

Can I pass enviroment variable from CircleCI to code in Spring Boot?

I want to put environment variables from CircleCI to application-production.properties file when deploying on Heroku.

application-production.properties

jwt.secret-key=${JWT_SECRET_KEY}

registration.url=${REGISTRATION_URL}

spring.mail.host=${MAIL_HOST}
spring.mail.port=${MAIL_PORT}
spring.mail.username=${MAIL_USERNAME}
spring.mail.password=${MAIL_PASSWORD}
spring.mail.properties.mail.smtp.auth=true
spring.mail.properties.mail.smtp.starttls.enable=true
spring.mail.properties.mail.smtp.starttls.required=true

application.properties (just to make sure I set profile right)

spring.profiles.active=production

.circleci/config.yml

version: 2.1

executors:
  java-version:
    docker:
      - image: 'cimg/openjdk:11.0.7'

orbs:
  maven: circleci/[email protected]
  heroku: circleci/[email protected]

workflows:
  build_deploy:
    jobs:
      - maven/test:
          executor: java-version
      - heroku/deploy-via-git:
          requires:
            - maven/test
          filters:
            branches:
              only: master

Heroku logs:

...
Caused by: java.lang.IllegalArgumentException: Could not resolve placeholder 'MAIL_HOST' in value "${MAIL_HOST}"
...

Did I miss something? What is the best approach to deal with credentials/sensitive data, and working with CI/CD?

It works locally (sending emails) and it pass build and deploy on CircleCI but when starting on Heroku it crash.

Upvotes: 1

Views: 1343

Answers (1)

Beppe C
Beppe C

Reputation: 13923

when deploying on Heroku it is good practise to use Config Vars to provide runtime configuration variables.

Make sure the variable names are UPPERCASE and match exactly what you define in the property file.

Upvotes: 1

Related Questions