[英]How to Inject property file in Jenkins and use it values in Java Code
I want to pass username and password in Jenkins by passing through property file and Use this credential in Java program to login to my app. 我想通过传递属性文件在Jenkins中传递用户名和密码,并在Java程序中使用此凭据登录我的应用程序。
OR, Other way around it, I can pass it as Password passing parameter for my jenkins job but I am not getting a way to fetch this password in my java program. 或者,换句话说,我可以将它作为密码传递参数传递给我的jenkins工作,但我没有办法在我的java程序中获取此密码。
Any help would be appreciated. 任何帮助,将不胜感激。 Thanks in advance.
提前致谢。
Step 1) prepare a java property file with username and password and put togerther with java code 步骤1)准备一个带有用户名和密码的java属性文件,并放入java代码
username = xxx
password = xxx
Step 2) Config jenkins job to inject environment variable from property file 步骤2)配置jenkins作业从属性文件中注入环境变量
Option 1: check Inject environment variables to the build process
under Build Environment
section 选项1:检查将
Inject environment variables to the build process
Build Environment
部分下Inject environment variables to the build process
Option 2: Add a Inject environment variable
build step and move it to the top on others build steps 选项2:添加
Inject environment variable
构建步骤,并将其移至其他构建步骤的顶部
For both options , specify the credential property file path relative to jenkins job workspace 对于这两个选项 ,请指定相对于jenkins作业工作空间的凭据属性文件路径
Step 3) specify system property: username and password in java cmd line 步骤3)指定系统属性:java cmd行中的用户名和密码
for example: java -DUserName="${username}" -DPassWord="${password}"
例如:
java -DUserName="${username}" -DPassWord="${password}"
Note : 注意 :
1. ${xxx}
, the xxx
from the key in property file, case sensitive. 1.
${xxx}
,来自属性文件中的键的xxx
,区分大小写。
2. Please use double quote in case username or password includes space 2.如果用户名或密码包含空格,请使用双引号
3. The pattern -Dxxx="${yyy}"
can work on both Execute linux shell
and Execute windows batch
build step. 3.模式
-Dxxx="${yyy}"
可以在Execute linux shell
和Execute windows batch
build步骤中工作。
More about Java command
更多关于Java命令
Step 4) obtain ssytem property: username and password in Java code 步骤4)获取ssytem属性:Java代码中的用户名和密码
String userName = System.getProperty("UserName")
// the parameter: "UserName" from -Dxxxx, also case sensitive
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.