Parameter types in template.yaml

2 minute read

When a developer creates a Pipeline job in CloudBees CI based on a Pipeline Template, the available parameters are displayed in the user interface as options for which the developer can specify a value.

string

In template.yaml

version: 1 type: pipeline-template name: A template with a single parameter parameters: - name: aParam type: string displayName: An individual parameter

In Jenkinsfile

echo "Hello ${aParam}"

number

In template.yaml

version: 1 type: pipeline-template name: Template with number Parameter description: A template with a single number parameter parameters: - name: someNumber displayName: A number type: number

In Jenkinsfile

echo "Remainder: ${someNumber % 2}"

boolean

In template.yaml

version: 1 type: pipeline-template name: A Declarative template with a boolean parameter parameters: - name: true_or_false displayName: A boolean parameter type: boolean

In Jenkinsfile

pipeline { agent any /* In the following stages, true_or_false is not surrounded by ${}. That's because the stages are using true_or_false in an expression. */ stages { stage('only-if-true') { when { expression { return true_or_false } } steps { echo "We ran the stage because true_or_false was true" } } stage('only-if-false') { when { expression { return !true_or_false } } steps { echo "We ran the stage because true_or_false was false" } } } }

credentials

When specifying a default value, use the ID for the credentials and not the actual secret. When the developer creates a job using the template, they will also specify the credentials ID. (You must set the ID through the Credentials Plugin or the Credentials Binding Plugin.

In template.yaml

version: 1 type: pipeline-template name: A Declarative template with a credentials ID parameter parameters: - name: github_creds displayName: GitHub Credentials ID type: credentials defaultValue: github-creds

In Jenkinsfile

pipeline { agent any stages { stage('echo id') { steps { echo "Credentials ID: ${CRED_ID}" } } } }