Uncodemy Logo ← Back to Course
Jenkins · Topic 13 of 15

Pipeline Parameters (String, Boolean, Choice)

Why Parameters in a Pipeline?

Instead of manually selecting parameters through the GUI every time, we can define them directly in the pipeline code using a parameters block placed right after agent.

String Parameter

pipeline {
    agent any
    parameters {
        string(name: "person", defaultValue: "Sandeep", description: "")
    }
    stages {
        stage('Hello') {
            steps {
                sh 'echo "hi my name is $person"'
            }
        }
    }
}

Boolean Parameter

pipeline {
    agent any
    parameters {
        booleanParam(name: "db", defaultValue: true, description: "")
    }
    stages {
        stage('Hello') {
            steps {
                sh 'echo "hi this is boolean parameters"'
            }
        }
    }
}

If defaultValue is true, the checkbox appears checked (enabled) on the Build with Parameters screen; false leaves it unchecked.

Choice Parameter

pipeline {
    agent any
    parameters {
        choice(name: "file", choices: ["sandeep", "chikkala", "sandy", "bablu"], description: "")
    }
    stages {
        stage('Choice Parameter') {
            steps {
                sh 'echo "touch $file"'
            }
        }
    }
}

On "Build with Parameters" you get a dropdown to pick one of the listed choices, which then feeds into the shell command.

Master Jenkins & DevOps with Uncodemy

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

Enroll in DevOps Training →