๐ฌ๐ง English | ๐จ๐ณ ็ฎไฝไธญๆ
๐ Stop scrolling through hundreds of stale Git branches when starting a Jenkins build.
Active Git Branches Parameter adds a build parameter that shows the branches your team is most likely to need first: recently updated branches, optionally filtered, capped, and protected from accidental selection.
It is designed for teams with busy repositories and many feature/release branches, where the normal branch dropdown quickly becomes noisy.
Important
To sort branches by recent commit activity, turn off useQuickFetch. The default (useQuickFetch: true) lists branches with ls-remote, which is fast but can only sort alphabetically. With useQuickFetch: false the plugin fetches just the latest commit of each branch into a cache repository on the controller and sorts by commit date. The first fetch takes a few seconds; after that only changed branch tips are transferred.
Most Git branch parameter solutions can list branches. This plugin focuses on making the list useful when the repository is busy.
- ๐ Find active work quickly: Put recently updated branches at the top instead of relying only on alphabetical sorting.
- ๐ Avoid dangerous branch picks: Keep protected branches visible but disabled with
excludeBranches, so users understand what exists without being able to select forbidden branches. - โญ Keep important branches visible: Force-show branches such as
main,develop, orrelease/.*withalwaysIncludeBranches, even when you limit the dropdown to the top N branches. - โ No Groovy scripts or script approval: Use a dedicated Java parameter instead of Active Choices scripts that run shell commands on the controller.
- ๐ Works with explicit repository URLs: Useful for Pipeline jobs where the repository is checked out inside the script, not declared in the job SCM configuration.
- ๐ชถ Light on the controller and Git server: Jobs pointing at the same repository share one cached branch list, refreshed at most once per minute.
- โก Fast after warm-up: Uses stale-while-revalidate caching so users see the last known branch list immediately while Jenkins refreshes in the background.
Use this plugin when:
- ๐ Many branches: Your branch list is long and users usually want the most recently updated branches.
- ๐งน Keep it simple: You want a simple branch-only parameter without maintaining Groovy scripts.
- ๐ Private repos: You need Jenkins credentials support for private repositories.
- ๐ก๏ธ Protect main: You want to discourage or block builds from
main,master, or release branches while still showing them in the UI. - ๐๏ธ Checkout in the Jenkinsfile: Your Pipeline checks out one or more repositories from inside the Jenkinsfile instead of the job SCM configuration.
If you need tags, pull requests, or arbitrary revisions, the mature Git Parameter Plugin may be a better fit.
If you need GitLab-specific API-based ref loading, consider GitLab Repository Refs Parameter.
- ๐ Dynamic branch fetching from a configured Git repository.
- โฐ Recent-activity sorting by branch commit date when quick fetch is disabled.
- ๐ Quick fetch mode for fast remote branch listing when commit timestamps are not required.
- ๐ข Configurable Top N limit to keep the dropdown focused.
- ๐ Regex branch filtering with Java regular expressions.
- โญ Always-include rules for important branches that must stay visible.
- ๐ซ Exclude/disable rules for branches that should be visible but not selectable.
- ๐ Jenkins Credentials integration for private repositories.
- โก Stale-while-revalidate cache for responsive Build with Parameters pages.
| Requirement | Version |
|---|---|
| ๐ต Jenkins | 2.541.3 or later |
| โ Java | 17 or later |
| ๐ Git Plugin | Latest recommended |
| Feature | Git Parameter | List Git Branches | Active Choices | Active Git Branches |
|---|---|---|---|---|
| ๐ Branch dropdown | โ | โ | โ | โ |
| ๐ท๏ธ Tags / PRs / revisions | โ | โ | โ | โ |
| ๐ Repo in parameter | โ | โ | โ | โ |
| โฐ Sort by recent activity | โ |
|
|
โ |
| ๐ Jenkins Credentials | โ | โ |
|
โ |
| ๐ซ No script approval needed | โ | โ | โ | โ |
| ๐ก๏ธ Disable protected branches in UI |
|
|
โ | โ |
Legend: โ
Full support ยท
Install Active Git Branches Parameter from Manage Jenkins โ Plugins โ Available plugins.
pipeline {
agent any
parameters {
activeGitBranches(
name: 'BRANCH',
repositoryUrl: 'https://github.com/your-org/your-repo.git',
credentialsId: 'github-credentials',
maxBranchCount: 10,
branchFilter: 'feature/.*',
alwaysIncludeBranches: 'main|develop',
excludeBranches: 'main|master',
description: 'Select a branch to build'
)
}
stages {
stage('Build') {
steps {
echo "Building branch: ${params.BRANCH}"
git branch: params.BRANCH,
url: 'https://github.com/your-org/your-repo.git',
credentialsId: 'github-credentials'
}
}
}
}
properties([
parameters([
activeGitBranches(
name: 'BRANCH',
repositoryUrl: 'https://github.com/your-org/your-repo.git',
maxBranchCount: 15,
description: 'Select a branch'
)
])
])
node {
stage('Build') {
echo "Selected branch: ${params.BRANCH}"
}
}
- ๐ง Go to your job's configuration page
- โ๏ธ Check "This project is parameterized"
- โ Click "Add Parameter" and select "Active Git Branches Parameter"
- โ๏ธ Configure the following options:
- ๐ท๏ธ Parameter Name: The name of the parameter (e.g.,
BRANCH) - ๐ Git Repository URL: The URL of your Git repository
- ๐ Credentials: Select credentials for private repositories (optional)
- ๐ข Max Branch Count: Maximum number of branches to display (default: 10)
- ๐ Branch Filter: Regular expression to filter branches (optional)
- โญ Always Include Branches: Regex for branches that must remain visible (optional)
- ๐ซ Exclude Branches: Regex for branches to show but disable (optional)
- ๐ Use Quick Fetch: Fast remote branch listing without commit-time sorting (default: enabled)
- โ๏ธ Allow Custom Branch: Allow users to type a branch name manually (optional)
- ๐ Default Value: Pre-selected branch (optional)
- ๐ท๏ธ Parameter Name: The name of the parameter (e.g.,
| Option | Required | Description |
|---|---|---|
name |
โ | Parameter name |
repositoryUrl |
โ | Git repository URL (HTTPS or SSH) |
credentialsId |
|
Jenkins credentials ID for private repositories |
maxBranchCount |
โ | Maximum number of branches to display (1-100) |
branchFilter |
|
Regular expression to filter branch names |
alwaysIncludeBranches |
|
Regex for branches that must always be included |
excludeBranches |
|
Regex to disable/prohibit selection of specific branches |
useQuickFetch |
|
true: fast ls-remote, alphabetical. false: fetch branch tips into a cache repository on the controller, sorted by commit date (default: true) |
defaultValue |
|
Default selected branch |
allowCustomBranch |
|
Allow users to type arbitrary branch name (default: false) |
description |
|
Parameter description |
Legend: โ
Required ยท
| Pattern | Description |
|---|---|
.* |
โ Match all branches |
feature/.* |
๐ฏ Only feature branches |
release/.* |
๐ Only release branches |
(main|master|develop) |
๐ณ Only main, master, or develop |
(?!release/).* |
โ Exclude release branches |
hotfix-.*|bugfix-.* |
๐ง Hotfix or bugfix branches |
- ๐ Page Load: When the Build with Parameters page loads, the plugin resolves branches for the configured repository. All Git operations run on the controller and never touch job workspaces.
- ๐ Quick Fetch (default): Lists remote branches with
ls-remote. Fast, but sorted alphabetically. - โฐ Time-sorted Fetch (quick fetch disabled): Fetches only the latest commit of each branch into a cache repository under
$JENKINS_HOME/caches/active-git-branches, then sorts by commit date. After the first fetch, only changed branch tips are downloaded. - ๐ค Apply Filters: The branch filter is applied, then
alwaysIncludeBranchesare preserved whilemaxBranchCountlimits the rest. - ๐ก๏ธ Disable Rules: Branches matching
excludeBranchesstay visible but are disabled, and server-side validation prevents bypassing the rule. - โก Smart Caching: Cached results are returned immediately. When the cached list is older than one minute, it is refreshed in the background. Jobs using the same repository, credentials and fetch mode share one cache entry.
- โ๏ธ Verify the repository URL is correct
- โ๏ธ Check that credentials are configured for private repositories
- โ๏ธ Use the "Test Connection" button in the configuration
๐ก Tip: Check Jenkins logs for detailed error messages
- โ๏ธ Enable
useQuickFetchto skip commit-date sorting - โน๏ธ With quick fetch disabled, the first load is slower because the branch tips are fetched into the cache repository
๐ก Tip: To change how often branch lists are refreshed, set the system property io.jenkins.plugins.activegitbranches.ActiveGitBranchesParameterDefinition.refreshIntervalSeconds (default 60)
- โ๏ธ Ensure credentials have read access to the repository
- โ๏ธ For GitHub, use a Personal Access Token instead of password
- โ๏ธ For SSH, ensure the SSH key is properly configured in Jenkins
๐ก Tip: Test credentials separately to isolate auth issues
Contributions are welcome! See CONTRIBUTING.md for how to build and test the plugin.
MIT License - see LICENSE for details.