【问题标题】:Using "secure" variables in Maven test command in Travis *.yml file在 Travis *.yml 文件的 Maven 测试命令中使用“安全”变量
【发布时间】:2017-01-30 06:16:29
【问题描述】:

所以我有一个.yml 文件,其中包含一些我需要传递给mvn clean test 命令的加密值的“安全”变量。

我有类似的东西

language: java
jdk:
  - oraclejdk8
env:
  global:
    # Output of the command, 'travis encrypt MY_SECRET_KEY=super_secret'
    - secure: Q0LjGCaS2LIB0z1XH1Qx4uAmGgG9mIlsZAtdSGbgd4XwRbWM5zPxaRtoe5YJCt4zeAOu9+TYxpqa5kv5EyizY0zSC8dEZQu6Ur7jfre2FaJ9O0sSq72Cn2cTVVXTEQi+CPnaK/pki/NpDSN6Zt82n7ypgxZOInFT+BtcXDK8ok0=
script: # Did I pass the secured variable correctly in the maven clean test command?
  - mvn clean test -Denvironment=QA -DsecretKey=$MY_SECRET_KEY

我传递了我在原始“Travis 加密”命令中使用的变量名。请看上面,我们应该如何传递加密的全局变量,以便在构建期间在maven clean test 命令中设置其解密值?

【问题讨论】:

  • 我对 maven 的细节一无所知,但除此之外,是的,你按预期使用了它。

标签: java maven encryption travis-ci


【解决方案1】:

您可以在 maven pom.xml 中评估环境变量,而不是在命令行中设置秘密变量,

请为这个变量输入你的 pom.xml 定义

<properties>
    <secretKey>${env.MY_SECRET_KEY}</secretKey>
</properties>

一个缺点是当你没有设置MY_SECRET_KEY 时,maven 不会解决这个问题。不过你可以看看这个问题:How can I use a default value if an environment variable isn't set for resource filtering in maven?

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-08-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多