List of Topics:
Location Research Breakthrough Possible @S-Logix pro@slogix.in

Office Address

Social List

How to Create a Jenkins Job that Reads and Prints Environment Variables During a Build?

Jenkins

Condition for Create a Jenkins Job that Reads and Prints Environment Variables During a Build

  • Description:
    Jenkins automatically provides several environment variables during a build, such as $JENKINS_HOME, $WORKSPACE, and $BUILD_NUMBER. These variables help you identify the Jenkins home directory, the job workspace, and the build number. By printing them in a job, you can verify the environment setup and use these variables in scripts or pipelines.

Steps

  •  Step 1 — Open Jenkins Dashboard
     Go to your browser and enter your Jenkins URL, e.g., http://localhost:8080
  •  Step 2 — Create a New Job
     Click New Item on the left menu
     Enter Job Name: env-test
     Select Freestyle Project → Click OK
  •  Step 3 — Add a Build Step
     Scroll to the Build section
     Click Add build step → Execute shell
  •  Step 4 — Enter Shell Script
     In the shell command box, type:
    echo "Jenkins Home: $JENKINS_HOME"
    echo "Workspace: $WORKSPACE"
    echo "Build Number: $BUILD_NUMBER"
  •  Step 5 — Save the Job
     Click Save at the bottom of the configuration page
  •  Step 6 — Run the Job
     Click Build Now on the left panel
     Jenkins will execute the shell script
  •  Step 7 — View the Build Output
     Under Build History, click the latest build → Console Output
     You should see something like:
    Jenkins Home: /var/lib/jenkins
    Workspace: /var/lib/jenkins/workspace/env-test
    Build Number: 1
    Finished: SUCCESS
  •  Goal
     The job successfully prints key Jenkins environment variables, which can be used for debugging, scripting, or dynamic configuration in builds.
Screenshots
  • 215
  • 216
  • 217
  • 218
  • 219
  • 220
  • 221