Expand Authors Top

If you have a few years of experience in the Java ecosystem and you’d like to share that with the community, have a look at our Contribution Guidelines.

Expanded Audience – Frontegg – Security (partner)
announcement - icon User management is very complex, when implemented properly. No surprise here.

Not having to roll all of that out manually, but instead integrating a mature, fully-fledged solution - yeah, that makes a lot of sense.
That's basically what Frontegg is - User Management for your application. It's focused on making your app scalable, secure and enjoyable for your users.
From signup to authentication, it supports simple scenarios all the way to complex and custom application logic.

Have a look:

>> Elegant User Management, Tailor-made for B2B SaaS

Generic Top

Get started with Spring 5 and Spring Boot 2, through the Learn Spring course:

>> CHECK OUT THE COURSE

1. Introduction

In this tutorial, we'll show the different ways to set and use environment variables in Jenkins.

To learn more about Jenkins and Pipelines, refer to our intro to Jenkins.

2. Global Properties

We can set global properties by navigating to “Manage Jenkins -> Configure System -> Global properties option”.

Let's first check the “Environment variables” checkbox and then add the variables and their respective values inside the “List of Variables” section:

Jenkins environment variables global properties

This is one of the easiest and least intrusive ways to set environment variables.

3. Jenkinsfile

We can set environment variables globally by declaring them in the environment directive of our Jenkinsfile.

Let's see how to set two variables, DISABLE_AUTH and DB_ENGINE:

Jenkinsfile (Declarative Pipeline)
pipeline {
    //Setting the environment variables DISABLE_AUTH and DB_ENGINE
    environment {
        DISABLE_AUTH = 'true'
        DB_ENGINE    = 'mysql'
    }

}

This approach of defining the variables in the Jenkins file is useful for instructing the scripts; for example, a Make file.

4. EnvInject

We can install and use the EnvInject plugin to inject environment variables during the build startup.

In the build configuration window, we select the “Inject environment variables” option in the “Add build step” combo box.

We can then add the required environment variables in the properties content text box.

For example, we can specify the user profile:

Inject Environment Variables

5. Usage

Now, we can use any of our environment variables by surrounding the name in ${}:

echo "Database engine is ${DB_ENGINE}"

6. Conclusion

In this article, we saw how to set and use environment variables in Jenkins.

Generic bottom

Get started with Spring 5 and Spring Boot 2, through the Learn Spring course:

>> CHECK OUT THE COURSE
Generic footer banner
Comments are closed on this article!