我可以将CircleCI中的环境变量传递给Spring Boot中的代码吗?

问题描述 投票:1回答:1

在Heroku上部署时,我想将CircleCI的环境变量放入application-production.properties文件。

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(只是为了确保我正确设置配置文件)

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日志:

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

我错过了什么吗?处理凭证/敏感数据以及使用CI / CD的最佳方法是什么?

[它在本地工作(发送电子邮件),并且在CircleCI上通过构建和部署,但是在Heroku上启动时崩溃。

spring heroku circleci
1个回答
0
投票

在Heroku上部署时,最好使用Config Vars提供运行时配置变量。

请确保变量名称为大写,并且与您在属性文件中定义的名称完全匹配。

© www.soinside.com 2019 - 2024. All rights reserved.