java Github操作在生成期间未识别机密值
我有一个Spring boot应用程序,它有一个api密钥。我已经在我的Github回购协议中设置了这个值 下面是秘密
EMAIL_API_KEY = 123
当我推送我的代码时,它开始构建,并在maven构建期间失败,出现以下错误
Error creating bean restHelper. Could not resolve placeholder 'EMAIL_API_KEY' in value "${EMAIL_API_KEY}"
在Spring boot中,我的应用程序中有如下值。属性文件
api_key=${EMAIL_API_KEY}
如何引用这个变量。秘密不是正确的位置吗?
我看不到设置环境变量和使用机密的选项。请给出建议。谢谢
更详细的错误日志
Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'emailController' defined in file [/../EmailController.class]: Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'restHelper' defined in file [/../RestHelper.class]: Unexpected exception during bean creation; nested exception is java.lang.IllegalArgumentException: Could not resolve placeholder 'EMAIL_API_KEY' in value "${EMAIL_API_KEY}"
GitHub操作的Yaml文件
name: CI/CD Pipeline
on:
push:
branches:
- 'main'
jobs:
test:
name: Test - Units & Integrations
runs-on: ubuntu-18.04
steps:
- uses: actions/checkout@v1
- name: Set up JDK 11
uses: actions/setup-java@v1
with:
java-version: 11.0.4
- name: Maven Package
run: mvn -B clean package # FAILS AT THIS STEP
- name: Maven Verify
run: mvn -B clean verify
# added this to test, same outcome.
env:
EMAIL_API_KEY: ${{ secrets.EMAIL_API_KEY }}
# 1 楼答案
你必须告知每项工作的环境变量
示例:
解释:
由于作业在不同的运行程序中运行,这些运行程序在不同的机器中运行。每个作业都在上运行指定的虚拟环境的新实例中运行
不可能在机器之间共享环境变量。Github操作还不支持在作业之间共享变量
然而,有些操作允许使用工件在作业之间共享数据。如果有意义的话,你最终可以使用它:github.com/marketplace/actions/share-jobs-data