#1 India's Top IT Training Institute

×

About Uncodemy

Know more about who we are and what we stand for.

About Us

About Us

Discover our mission to equip individuals with essential IT skills and industry expertise.

Read More →
UnCodeMy Gallery

UnCodeMy Gallery

Explore highlights from our IT training sessions and success stories.

Read More →
×

Free Resources

Learn, practice and plan your career — bilkul free.

Tutorials

Tutorials

Step-by-step written tutorials to learn any technology at your own pace.

Read More →
Free Counselling

Free Counselling

Book a free video counselling session and pick the right course for you.

Read More →
Online Compiler

Online Compiler

Write, run and test your code online — no setup required.

Read More →
Jenkins · Topic 12 of 15

Pipeline Variables: Global & Local

Two Types of Variables

Variables are used to store values/data inside a pipeline. Jenkins declarative pipelines support two kinds:

  1. Global variable
  2. Local variable

Global Variable

Declared in an environment block right after agent. Referenced anywhere in the stages using $variableName.

pipeline {
    agent any
    environment {
        name = "Sandeep Chikkala"
    }
    stages {
        stage('Hello') {
            steps {
                echo "hi, my name is $name"
            }
        }
    }
}

Multiple Global Variables

environment {
    name = "Sandeep Chikkala"
    topic = 'DevOps'
    platform = 'linkedin'
    duration = 90
}
stages {
    stage('Multiple Global Variables') {
        steps {
            echo "hi, my name is $name, I'm teaching $topic through $platform."
            echo "And the course duration is $duration days"
        }
    }
}

Local Variable

A local variable is declared inside a specific stage and overrides the global variable for that stage only.

pipeline {
    agent any
    environment {
        name = "Sandeep"
    }
    stages {
        stage('Hello') {
            steps { echo "hi, my name is $name" }
        }
        stage("local variable") {
            environment {
                name = "SandeepChikkala"
            }
            steps { echo "hii, I'm $name" }
        }
    }
}

Use a local variable whenever one particular stage needs a different value than the rest of the pipeline.

Master Jenkins & DevOps with Uncodemy

Hands-on live training, real projects, and placement support — become job-ready in DevOps.

Enroll in DevOps Training →