Skip to content

Parametrized pipelines

Patrick O'Hannigan edited this page Nov 15, 2016 · 11 revisions

You can define pipelines as requiring some parameters (from the user, or from an API call) before they can start. These parameters can control what the pipeline does, for example, what environment it may be deploying applications into.

Parameters

pipeline {
    agent any
    
    parameters {
        booleanParam(defaultValue: true, description: '', name: 'flag')
    }
    
    stages {
        stage("foo") {
            steps {
                echo "flag: ${env.FLAG}"
            }
        }
    }
}

This will ask for a true/false value when the pipeline is run.

You can also ask for string input:

stringParam(defaultValue: true, description: '', name: 'flag')

You can also ask for multiple choice items, and stack up the input required:

    parameters {
        stringParam(defaultValue: "TEST", description: 'What environment?', name: 'flag')
        choiceParam(choices: 'US-EAST-1\nUS-WEST-2', description: 'What AWS region?', name: 'region')
    }

The choices string is newline separated.