Search code examples
gitjenkinspipelinegit-tag

Jenkins pipeline parameters


So I have defined a Jenkins pipeline that only runs the build when I'm passing a git tag as a string. Is there a way to list all the tags from a specific branch in a dropdown in order to select the one I want to build?


Solution

  • There are two nice options that you can use:

    • You can use the Git Parameter Plugin which integrates with your SCM step configuration and allows you to exposes parameters that are related to the defined repository - you can easily create a select list of available branches, tags, revisions or pull requests according to your needs.
      This plugin is best to use if you already have a SCM configuration in your job, as it draws the repository information for that configuration. List item

    • The second option is to use List Git Branches Parameter Plugin, this plugin also adds ability to create a parameter that allows to choose branches, tags or revisions from a configured git repository, but unlike the Git Parameter Plugin, this plugin requires a git repository defined instead of reading GIT SCM configuration from your projects.
      in addition this plugin will not change the workspace at all at build-time. enter image description here

    To sum up: when you already have a SCM configuration in your job the Git Parameter is the perfect choice, but sometimes we want to specify a git branch or tag as a parameter before the execution starts, for "Pipeline script" jobs (not "Pipeline script from SCM") that use SCM in the script, it is impossible with Git Parameter Plugin. In this particular case, a plugin that can list remote git branches or tags without defining SCM in the job is needed and the List Git Branches Parameter Plugin can achieve that.