How to mask parameters and password in Jenkins build history? - jenkins

When using Password parameter to accept user credentials,
Jenkins Build History -> Parameters is showing Password in plain text.
How to mask it?

You can use the regular password parameter type, for example using parameters defined in the jenkinsfile: https://jenkins.io/doc/book/pipeline/syntax/#parameters
The problem with that one is that, even if it masks the password when you access the "Parameters" section of a build and when you write it on "Build with parameters", if at any point that value is printed in the logs, it is shown.
To avoid that you have the Mask Passwords Plugin as said previously by
Javier C.. The problem with that one is that the plugin at the moment of writing this answer is up for adoption and has security vulnerabilities.

You can use Mask Passwords Plugin.
With this plugin, passwords don't appear as plain text in the job configuration or in the console.

Related

Is there a way to unmask asteriks between words in jenkins console?

I understood that reason for having asteriks in jenkins console output is because of using credentials method(Eg. for maven command). 
This credentials method will mask only credentials used with asteriks in jenkins console.
But in my case it is masking the space between two words also with 4 asteriks. 
Expecting normal spaces between two words instead of having asteriks while using credentials method in jenkinsfile

How to select password from dropdown and pass it as parameter to jenkins job?

I have a problem. I use Jenkins to deploy application on machines. Depending on which machine i want to deploy new version I need to use different database passwords to run db migrations. I want to store credentials in Jenkins and for each deploy job select credentials set from dropdown which will be passed (just password ) to powershell script. I have Credentials Binding Plugin and Extended Choice Parameter Plugin. I thought it might help me with my problem, but I cannot find solution for this. Do you have any ideas how to achieve this?
As I understand, you need only to do two things:
add Credential Parameter in This project is parameterized section for possibility to select credentials set from dropdown.
enable Use secret text(s) or file(s) option in Build Environment section. This will allow you to take credentials of various sorts and use them from shell build steps and the like. Each binding will define an environment variable.
If you have already created Jenkins credentials like these:
then you will be available to run your job using Build with Parameters button and select needed credentials:
So, after configuring, you don't need to dig in job configuration each time, all possible credentials will be automatically loaded, you need only select the needed one when run a job.

Does Jenkins have a feature like credentials for non-secrets?

real simple question today.
Does Jenkins have a feature like credentials that is for non-secret information?
My use case is that I want to specify some values in jenkins to make them easily available to all of my pipelines. (e.g. an Azure subscription id) I tried to just use 'secret text' type credentials, but the magic that jenkins does to protect those credentials make it difficult to work with them.
I imagine it would be called something like global environment variables, or named values, but I haven't been able to find anything with my googling.
Thanks!
The following steps will help you setup global environment variables which can be used within various builds and pipelines. The steps may be slightly different based on the version of Jenkins installed. The steps noted below are based on version 2.7.4:
Navigate to Manage Jenkins on the left side menu
Click "Configure System"
Scroll down to find "Global properties"
Check "Environment variables"
Click "Add"
Add the name and value in correct input area (Example: arg_name & arg_value)
Click "Save" at the bottom of the page
To use this global environment variable, navigate to an input area within a build definition and use: ${arg_name}

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

My aim:
To use a password in jenkins which is masked after input and runtime.
I only need it for my job.
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?
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.
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

Password not getting masked in jenkins

i am using jenkins masking plugin to mask the passwords.
I have an user (i054564) defined in credentials as username/password type
The user name /password is defined in the bindings section as well as in the mask password subsection of Build environment section.So whenever i am using that user/password in my build job as a variable, the password is not masked and logged in the console
Some snapshots have been attached to depict the problem
Snapshot -1 Build specific settings
Snapshot -2 Credentials settings
Snapshot -3 Manage Jenkins Mask password settings
Strange thing is initially it works and then after 2-3 builds it stops working.
please let me know if you need any further details
best Regards,
Saurav
You can use "Inject passwords to the build as environment variables" from Build Environment and defined its value as your "password parameter". ( password parameter - for which you can ask user to enter the password at run time). (e.g.: define inject password value as : ${password_parameter} ).
The password which you will pass while running job will display as [*******]

Resources