Use jenkins to inject masked password for use in code within the build

别来无恙 提交于 2019-12-11 07:39:35

问题


My aim:

  1. To use a password in jenkins which is masked after input and runtime.
  2. I only need it for my job.
  3. I can use it in my java code to login to a website.

Areas I have looked at:

The credentials plugin - this looks like the right area (but I'll need to get the sysadmins to add me as its locked down).

Also I can't find out how you can access the output?


回答1:


Have a look into the EnvInject plugin, there you can define password parameters that are masked in console output and job configuration, they can be used like normal parameters.

The screenshot shows the configuration in the job to use a local password.

The shell script build step I used is

echo "myPassword = $myPassword"

The resulting console output is:

+ echo 'myPassword = [*******]'
myPassword = [*******]

To pass it to Java you can use it like any other parameter from the job configuration. The value itself is encrypted, so checking the job configuration as XML will not reveal the password either.




回答2:


You can use the jenkins credentials binding plugin.

After installing the Credentials Bindings plugin, the Build Environment section of your build job Configuration page will include a new option:

Use secret text(s) or file(s)

Enabling this option allows you add credential bindings where the Variable value will be used as the name of the environment variable that your build can use to access the value of the credential.

See the full description of all steps here: https://support.cloudbees.com/hc/en-us/articles/203802500-Injecting-Secrets-into-Jenkins-Build-Jobs



来源:https://stackoverflow.com/questions/44697663/use-jenkins-to-inject-masked-password-for-use-in-code-within-the-build

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!