Skip to main content
← Back to workflows

How to Manage Jenkins Environment Variables More Effectively?

envinject -
Jenkins Plugin
v.2.908.v66a_774b_31d93
Required Jenkins: v.2.361.4
ID: envinject
GitHub Org's stars
Contributors
Categories
CICube banner
The GitHub Actions dashboard helps you spot bottlenecks and optimize your CI pipeline with actionable insights.
Installation with the CLI tool
jenkins-plugin-cli --plugins envinject:2.908.v66a_774b_31d93

envinject-plugin logo

envinject-plugin

This plugin makes it possible to setup a custom environment for your jobs


What is Environment Injector Plugin?

This plugin eliminates inherited environment variables from the Jenkins Java process. It injects environment variables during node (controller/agent) startup and offers flexibility by executing setup scripts before and/or after SCM checkout for a run. Additionally, it allows injection of environment variables as build steps and ensures secure handling of password values. At the conclusion of each build, it automatically exports environment variables, offering visibility into the utilized environment variables for every build.

Use Cases for Environment Injector Plugin

Use Cases

The Environment Injector Plugin offers versatile use cases to streamline environment configuration in Jenkins jobs:

  1. Removing Inherited Environment Variables:

    • Remove default environment variables (e.g., PATH, ANT_HOME) at the node level (controller/agent) for a job run.
  2. Variable Injection:

    • Inject variables in the initial step of the job, before the SCM checkout.
    • Inject variables dynamically based on user parameter values.
  3. Script Execution:

    • Execute an initialization script before or after an SCM checkout.
  4. Build Step Integration:

    • Inject variables as a build step, sourced from a file populated by a preceding build step.
  5. Environment Visibility:

    • Access a log of environment variables utilized for each build.
  6. Build Cause Integration:

    • Inject build cause as an environment variable for a build.
  7. Scripted Configuration:

    • Dynamically inject environment variables from the evaluation of a Groovy script, powered by the Script Security Plugin.
  8. Metadata Export:

    • Export environment variables as metadata in your binary repository for comprehensive build documentation.

How to Use Environment Injector Plugin in Jenkins?

Job Level Configuration

Setting Up a Clean Environment:

At the job level, users can configure a clean environment for their Jenkins jobs. This ensures a pristine workspace for each job run, devoid of any residual artifacts or dependencies from previous builds. A clean environment promotes consistency and reproducibility in the build process, minimizing the risk of conflicts or unexpected behavior arising from lingering state.

At node (controller and agent) level

To achieve this, users can leverage the Environment Injector Plugin to remove inherited environment variables and inject custom variables tailored to the specific requirements of the job. By establishing a clean environment at the outset of each job run, teams can maintain a standardized and reliable build environment, facilitating seamless integration and deployment workflows.

Injecting Variables after SCM Checkout

In Jenkins job configurations, users can inject variables after performing an SCM (Source Code Management) checkout. This feature provided by the Environment Injector Plugin allows for dynamic configuration of the build environment based on the state of the checked-out source code.

Injecting Variables after SCM Checkout

Injecting Variables as a Build Step

The Environment Injector Plugin in Jenkins empowers users to inject variables seamlessly as a build step within their job configurations. This functionality facilitates the dynamic manipulation of the build environment, allowing users to set up custom variables, define parameters, or execute scripts as part of the build process.

Injecting Variables after SCM Checkout

Monitoring GitHub Actions Workflows

CICube is a GitHub Actions monitoring tool that provides you with detailed insights into your workflows to further optimize your CI/CD pipeline. With CICube, you will be able to track your workflow runs, understand where the bottlenecks are, and tease out the best from your build times. Go to cicube.io now and create a free account to better optimize your GitHub Actions workflows!

CICube GitHub Actions Workflow Duration Monitoring