liveBook · Manning

Environment variable

As explained in Practical Automation with PowerShell: Effective scripting from the console to the cloud

An environment variable is a named value supplied by an operating-system or process environment to applications and scripts.

An environment variable supplies a named value from the process environment to an application or script. In Jenkins, it provides the parameter-passing mechanism when command-line parameters are unavailable. section 3.2.4

PowerShell reads Jenkins variables through the $env: scope. Replacing a script's parameter block with values such as $env:logpath preserves existing variable usage while adapting the script to scheduled execution. section 3.2.4

Use environment variables to:

  • Pass configurable paths, prefixes, and retention values into a scheduled Jenkins job. section 3.2.4
  • Supply Jenkins-managed credentials and secret text at execution time. section 4.4.2
  • Reconstruct PowerShell SecureString or PSCredential objects when Jenkins provides secret values as ordinary strings. section 4.4.2

Jenkins-driven log cleanup

A PowerShell cleanup script can assign $LogPath, $ZipPath, $ZipPrefix, and $NumberOfDays from $env:logpath, $env:zippath, $env:zipprefix, and $env:numberofdays. Jenkins then supplies matching string parameters and runs the job on a schedule. section 3.2.4

$LogPath = $env:logpath
$ZipPath = $env:zippath
$ZipPrefix = $env:zipprefix
$NumberOfDays = $env:numberofdays

This listing shows the compact PowerShell pattern for mapping Jenkins environment variables to the script's existing parameter names. section 3.2.4

How Practical Automation with PowerShell: Effective scripting from the console to the cloud covers it

How deep it goes
Explains PowerShell access, lowercase Jenkins names, parameter replacement, credential bindings, and SecureString reconstruction.
Examples
Uses log-cleanup paths and retention settings plus SQL health-check credentials, server names, and SendGrid values.
What it assumes
Assumes PowerShell scripting and Jenkins familiarity while demonstrating the required bindings and environment-variable substitutions.
What you can do after
Operate/configure Jenkins jobs that pass script parameters and credentials through PowerShell environment variables.
How it connects
Connects PowerShell parameters, Jenkins, scheduled jobs, credential bindings, SecureString, and PSCredential.

Also explained in

Compare how 19 books explain environment variable →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Practical Automation with PowerShell: Effective scripting from the console to the cloud. The section links point to the parts of the book it draws on.