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

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

Introduction In 2026, the importance of accounting software continues to grow, helping businesses of all sizes streamline financial management, improve accuracy, and stay compliant with ever-changing regulations….

Read More

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

Introduction In 2026, businesses of all sizes are increasingly reliant on a variety of devicesโ€”laptops, desktops, mobile devices, and other endpointsโ€”that connect to their networks. With the…

Read More

Top 10 Order Management Systems Tools in 2026: Features, Pros, Cons & Comparison

Introduction In 2026, managing orders has become a sophisticated process, requiring advanced tools to handle large volumes, multiple sales channels, and intricate supply chains. Order Management Systems…

Read More

What is Veracode and use cases of Veracode?

What is Veracode? Veracode is a leading application security (AppSec) platform that helps organizations identify and remediate vulnerabilities in their software throughout the development lifecycle. By integrating…

Read More

Terraform Backend Tutorial

Terraform is a popular open-source infrastructure as code tool used to create and manage infrastructure resources. The state of the infrastructure resources managed by Terraform is stored…

Read More

Best Tools for Software Composition Analysis (SCA)

Hereโ€™s a clear and professional explanation of the three related concepts you asked about โ€” all of which are critical parts of secure software development, especially in…

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