I want to list my branches as parameter in Jenkins. It's possible in the freestyle job (using the git parameter plugin). But I don't know how to make it work inside a pipeline?
The plugin tells us they have added pipeline support but there isn't an example somewhere.
For a declarative Pipeline, you can add a git Parameter like this:
pipeline{
agent any
parameters {
gitParameter(
branch: '',
branchFilter: ".*",
defaultValue: "",
description: '',
listSize: '10',
name: 'Version',
quickFilterEnabled: false,
selectedValue: 'NONE',
sortMode: 'ASCENDING_SMART',
tagFilter: "*",
type: 'PT_BRANCH_TAG',
useRepository: '[email protected]:foo/bar.git')
}
stages{
stage ("echo Git Tag") {
steps {
echo "${params.Version}"
}
}
}
}
The example above will show you all branches and tags available on the repo. if you want to display only tags, change the type to
type: 'PT_TAG'
if you only want to show specific tags you can filter, for example, only show tags that start with "foo"
tagFilter: "foo*"
If you want to see more details, just check out the Pipeline Syntax Generator. you will find this at:
Sample Step -> properties -> This project is parameterised -> add Parameter -> git Parameter
I advice you to please go through multi-branch pipeline plugin
Let's say you have more than one branch available in GIT. Creating a multi-branch pipeline Job allows you to distinguish and run branch based Jenkins Jobs under single project.
Apart from GIT, It also support Bit-bucket, GitHub, Subversion, Mercurial, Single repository & branch.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With