# Using Parameters in Jenkins Pipelines

In 
Published 2022-12-03

This tutorial explains to you how we can use Parameters in Jenkins Pipelines.

First of all I want to highlight that a prerequisite for this article is Create Declarative Pipeline tutorial.

Now we modify the Jenkinsfile in GitHub. The new Jenkinsfile will be like this:

pipeline {
    agent any
    
    parameters {
        string(name: 'Parameter1', defaultValue: 'Hello', description: 'This is the first parameter')

        text(name: 'Message', defaultValue: '', description: 'Enter a message')
        booleanParam(name: 'TrueOrNot', defaultValue: true, description: 'Is it true or false ?')
        choice(name: 'YourChoice', choices: ['One', 'Two', 'Three'], description: 'Pick a number')
        password(name: 'PASSWORD', defaultValue: 'SECRET', description: 'Enter a password')
    }

    stages {
        stage('Build') {
            steps {
                echo 'Building...'
                echo "${params.Parameter1} World!"
                echo "Message=${params.Message}"
                echo "TrueOrNot= ${params.TrueOrNot}"
                echo "YourChoice= ${params.YourChoice}"
                echo "PASSWORD= ${params.PASSWORD}"
            }
        }
        stage('Test') {
            steps {
                echo 'Testing...'
            }
        }
        stage('Deploy') {
            steps {
                echo 'Deploying...'
            }
        }
    }
}

We run the pipeline.

After that, we will see that instead "Build Now" button we have "Build with Parameters" button:

We press on "Build with Parameters" button, and we will see :

We input the parameter values and after that we can press on "Build" button.

When we are looking into the console output we can see :

Building...
[Pipeline] echo
Hello World!
[Pipeline] echo
Message=
[Pipeline] echo
TrueOrNot= true
[Pipeline] echo
YourChoice= One
[Pipeline] echo
Warning: A secret was passed to "echo" using Groovy String interpolation, which is insecure.
Affected argument(s) used the following variable(s): [PASSWORD]
See https://jenkins.io/redirect/groovy-string-interpolation for details.
PASSWORD= SECRET

More information about using parameters we can get from here.