Password not getting masked in jenkins - 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 [*******]

Related

Git checking out external project in jenkins pipeline using user and password

Reading this answer the way of checking out an external project from a jenkins pipeline is as follows:
git branch: 'master',
credentialsId: '12345-1234-4696-af25-123455',
url: 'ssh://git#bitbucket.org:company/repo.git'
The author of the post also says:
If you're using the ssh url then your credentials must be username + private key. If you're using the https clone url instead of the ssh one, then your credentials should be username + password.
However, not fully clear how the second case works (https URL and username + password)... Which syntax is use in this case for creadentialsId? Or that field is not used and others are used to specify username and password? Could somebody provide an example of it, please?
Thanks!
Store the username and password on Jenkins by following:
https://www.jenkins.io/doc/book/using/using-credentials/
Adding new global credentials To add new global credentials to your
Jenkins instance:
If required, ensure you are logged in to Jenkins (as a user with the
Credentials > Create permission). From the Jenkins home page (i.e. the
Dashboard of the Jenkins classic UI), click Manage Jenkins > Manage
Credentials. image
Under Stores scoped to Jenkins on the right, click on Jenkins. image
Under System, click the Global credentials (unrestricted) link to
access this default domain. image
Click Add Credentials on the left. Note: If there are no credentials
in this default domain, you could also click the add some credentials
link (which is the same as clicking the Add Credentials link). From
the Kind field, choose the type of credentials to add. From the Scope
field, choose either: Global - if the credential/s to be added is/are
for a Pipeline project/item. Choosing this option applies the scope of
the credential/s to the Pipeline project/item "object" and all its
descendent objects. System - if the credential/s to be added is/are
for the Jenkins instance itself to interact with system administration
functions, such as email authentication, agent connection, etc.
Choosing this option applies the scope of the credential/s to a single
object only. Add the credentials themselves into the appropriate
fields for your chosen credential type: Secret text - copy the secret
text and paste it into the Secret field. Username and password -
specify the credential’s Username and Password in their respective
fields. Secret file - click the Choose file button next to the File
field to select the secret file to upload to Jenkins. SSH Username
with private key - specify the credentials Username, Private Key and
optional Passphrase into their respective fields. Note: Choosing Enter
directly allows you to copy the private key’s text and paste it into
the resulting Key text box. Certificate - specify the Certificate and
optional Password. Choosing Upload PKCS#12 certificate allows you to
upload the certificate as a file via the resulting Upload certificate
button. Docker Host Certificate Authentication - copy and paste the
appropriate details into the Client Key, Client Certificate and Server
CA Certificate fields. In the ID field, specify a meaningful
credential ID value - for example,
jenkins-user-for-xyz-artifact-repository. The inbuilt (default)
credentials provider can use upper- or lower-case letters for the
credential ID, as well as any valid separator character, other
credential providers may apply further restrictions on allowed
characters or lengths. However, for the benefit of all users on your
Jenkins instance, it is best to use a single and consistent convention
for specifying credential IDs. Note: This field is optional. If you do
not specify its value, Jenkins assigns a globally unique ID (GUID)
value for the credential ID. Bear in mind that once a credential ID is
set, it can no longer be changed. Specify an optional Description for
the credential/s. Click OK to save the credentials
Then, use the ID from that in the credentialsId field in the code above.

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.

jenkins Could not set the value of environment variable 'BUILD_USER'

i'm using jenkins to build android project,
however i always got below error: "* What went wrong:Could not set the value of environment variable 'BUILD_USER': could not convert string to current locale"
i don't know where is environment variable 'BUILD_USER',i am confused why could not set it. can anyone please help?
BUILD_USER comes from the Build User Vars plugin. It should be the First and Last name of the user who triggered the build (as defined in the Security Realm, i.e. LDAP, internal DB, etc.).
I am guessing that there is some character in the name of the user that doesn't agree with the locale configured in your Jenkins environment. You could disabled that plugin (remove the checkbox next to it in the "Manage Plugins" page), and see if the error goes away. Then you can troubleshoot from there.

How to mask parameters and password in Jenkins build history?

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.

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

Resources