Find the Best Cosmetic Hospitals

Explore trusted cosmetic hospitals and make a confident choice for your transformation.

โ€œInvest in yourself โ€” your confidence is always worth it.โ€

Explore Cosmetic Hospitals

Start your journey today โ€” compare options in one place.

Jenkins Tutorials: Variables in Scripted Pipeline

In a scripted Jenkins pipeline, you can use different types of variables depending on your requirements. Here are examples of different variable types commonly used in scripted pipelines:

In a scripted pipeline, you can define variables using the def keyword. Here’s an example of how to define a variable in a scripted Jenkins pipeline:


node {
    stage('Example') {
        // Define variable using def
        def myVariable = "Hello, Jenkins!"

        // Access and use the variable
        echo myVariable

        // You can also use the variable in conditional statements or within steps
        if (myVariable == "Hello, Jenkins!") {
            echo "Variable value matches!"
        } else {
            echo "Variable value does not match!"
        }
    }
}
Code language: PHP (php)

In the above example, we define a variable myVariable using the def keyword and assign it the value "Hello, Jenkins!". We then echo the variable’s value and demonstrate its usage within an if statement.

Note that the node block is used to allocate a Jenkins agent to execute the pipeline steps. Inside the stage block, you can define and use variables as needed.


Types of variables in Scripted Pipeline

String Variable:


node {
    stage('Example') {
        // Define a string variable
        def myString = "Hello, Jenkins!"

        // Access and use the string variable
        echo myString
    }
}
Code language: PHP (php)

Integer Variable:


node {
    stage('Example') {
        // Define an integer variable
        def myInteger = 10

        // Access and use the integer variable
        echo myInteger
    }
}
Code language: PHP (php)

Boolean Variable:


node {
    stage('Example') {
        // Define a boolean variable
        def myBoolean = true

        // Access and use the boolean variable
        if (myBoolean) {
            echo "The boolean variable is true."
        } else {
            echo "The boolean variable is false."
        }
    }
}
Code language: PHP (php)

List Variable


node {
    stage('Example') {
        // Define a list variable
        def myList = ["apple", "banana", "orange"]

        // Access and use the list variable
        for (item in myList) {
            echo item
        }
    }
}
Code language: PHP (php)

Map Variable:


node {
    stage('Example') {
        // Define a map variable
        def myMap = [name: "John", age: 30, city: "New York"]

        // Access and use the map variable
        echo "Name: ${myMap.name}"
        echo "Age: ${myMap.age}"
        echo "City: ${myMap.city}"
    }
}
Code language: PHP (php)

Find Trusted Cardiac Hospitals

Compare heart hospitals by city and services โ€” all in one place.

Explore Hospitals
Iโ€™m a DevOps/SRE/DevSecOps/Cloud Expert passionate about sharing knowledge and experiences. I have worked at <a href="https://www.cotocus.com/">Cotocus</a>. I share tech blog at <a href="https://www.devopsschool.com/">DevOps School</a>, travel stories at <a href="https://www.holidaylandmark.com/">Holiday Landmark</a>, stock market tips at <a href="https://www.stocksmantra.in/">Stocks Mantra</a>, health and fitness guidance at <a href="https://www.mymedicplus.com/">My Medic Plus</a>, product reviews at <a href="https://www.truereviewnow.com/">TrueReviewNow</a> , and SEO strategies at <a href="https://www.wizbrand.com/">Wizbrand.</a> Do you want to learn <a href="https://www.quantumuting.com/">Quantum Computing</a>? <strong>Please find my social handles as below;</strong> <a href="https://www.rajeshkumar.xyz/">Rajesh Kumar Personal Website</a> <a href="https://www.youtube.com/TheDevOpsSchool">Rajesh Kumar at YOUTUBE</a> <a href="https://www.instagram.com/rajeshkumarin">Rajesh Kumar at INSTAGRAM</a> <a href="https://x.com/RajeshKumarIn">Rajesh Kumar at X</a> <a href="https://www.facebook.com/RajeshKumarLog">Rajesh Kumar at FACEBOOK</a> <a href="https://www.linkedin.com/in/rajeshkumarin/">Rajesh Kumar at LINKEDIN</a> <a href="https://www.wizbrand.com/rajeshkumar">Rajesh Kumar at WIZBRAND</a> <a href="https://www.rajeshkumar.xyz/dailylogs">Rajesh Kumar DailyLogs</a>

Related Posts

The 5 Most Popular Email APIs Among Developers In 2026

In the modern world, where everything is going digital, email is among the most important means of communication both in personal and business life. As a developer,…

Read More

Top 10 Construction Management Software Tools in 2026: Features, Pros, Cons & Comparison

Introduction Construction Management Software (CMS) has become indispensable in 2026 for efficiently handling various aspects of construction projects, ranging from budgeting, scheduling, resource allocation, project tracking, to…

Read More

Top 10 Loan Management Software Tools in 2026: Features, Pros, Cons & Comparison

Introduction As the financial services sector continues to evolve, Loan Management Software (LMS) plays a pivotal role in helping businesses streamline their loan operations, from origination to…

Read More

Top 10 AI Presentation Design Tools in 2026: Features, Pros, Cons & Comparison

Introduction In 2026, AI presentation design tools have become indispensable for professionals, educators, and students aiming to create visually stunning and impactful slide decks with minimal effort….

Read More

Top 10 Web Design Software Tools in 2026: Features, Pros, Cons & Comparison

Introduction Web design software is a vital tool for both professionals and businesses looking to create visually appealing and functional websites. In 2026, with the increase in…

Read More

Top 10 AI Graphic Design Tools in 2026: Features, Pros, Cons & Comparison

Introduction In 2026, AI graphic design tools have transformed the creative landscape, empowering designers, marketers, and business owners to produce stunning visuals with unprecedented speed and efficiency….

Read More
Subscribe
Notify of
guest
1 Comment
Newest
Oldest Most Voted
Inline Feedbacks
View all comments
rakesh
rakesh
2 years ago

thanks for sharing all types of variables Scripting pipeline that developer use regularly that helps lot

1
0
Would love your thoughts, please comment.x
()
x