How to Inject a Password as Environment Variable in Jenkins

The main reason we are going to see how to inject a password as environment variable in Jenkins is that we need to abate security risks.

If you are required to pass your password as an input parameter with the password being an environment variable, you should not directly pass it as a parameter. One of the main reasons being, it is a password. Anyone having access to the job can see what the password is.

A password needs to be hidden or encrypted, so that no one but the admin who has created the job could get access.

So what is the correct way of passing the password in Jenkins?

There is something called injecting password as environment variable in jenkins that basically ensures your password is only accessible to the person who has configured your job.

I have written a quick security tip – a tutorial on how to inject a password as environment variable in Jenkins. Go ahead and follow the steps.

Steps on How to Inject a Password as Environment Variable in Jenkins

Once you are in your project, follow the below written steps in order to inject password as Environment Variable in Jenkins:

Step 1: Click on Configure.

click on configure option

Step 2: Scroll down below and look for Build Environment section. There look for the “Inject passwords to the build as environment variables” checkbox.

How to Inject a Password as Environment Variable in Jenkins option

Step 3: Check the box that says inject passwords to the build as environment variables.

When you do that you will notice some options flaring up.

inject passwords to build as environment variables

If you wish to make the password global, you can check the global passwords checkbox. You can see another checkbox saying “Mask password parameters”. If checked it would apply a mask and hide your password too from the rest of the people visiting this configuration page.

Step 4: Once ready, click on Add button to add a password.

where you need to enter name and passwords

Step 5: You will notice Name and Password text fields would open. Just provide the environment variable name in the Name field and the password for it, in the Password field.

Step 6: Once you have entered the details, you can click on Apply, then Save.

variable and password save in How to Inject a Password as Environment Variable in Jenkins

Once it gets saved, you are done.

How to Inject a Password as Environment Variable in Jenkins final location

It is that easy!

Go ahead and follow all the steps I have mentioned in the How to Inject a Password as Environment Variable in Jenkins tutorial and stow away your passwords in a safer environment, instead of having them lying around and accessible to hackers.

Check out our other cool tutorials on our website.

Scottshak

Poet. Author. Blogger. Screenwriter. Director. Editor. Software Engineer. Author of "Songs of a Ruin" and proud owner of four websites and two production houses. Also, one of the geekiest Test Automation Engineers based in Ahmedabad.

You may also like...

Leave a Reply