A Jenkins plugin that provides a build parameter for selecting Git branches dynamically fetched from a remote repository, sorted by commit date (most recent first), with configurable filtering and limiting options.
- Dynamic Branch Fetching: Automatically fetches branches from a Git repository at build time
- Sorted by Activity: Branches are sorted by commit date in descending order (most recent first)
- Configurable Limit: Limit the number of displayed branches (Top N)
- Regex Filtering: Filter branches using regular expressions
- Credentials Support: Integrates with Jenkins Credentials for private repositories
- No Script Approval Required: Pure Java implementation, no Groovy scripts or sandbox approval needed
- Jenkins 2.387.3 or later
- Java 11 or later
- Git Plugin
- Clone this repository
- Build the plugin:
mvn clean package
- Install the generated
.hpifile fromtarget/active-git-branches-plugin.hpivia Jenkins Plugin Manager
(Coming soon)
pipeline {
agent any
parameters {
activeGitBranches(
name: 'BRANCH',
repositoryUrl: 'https://github.com/your-org/your-repo.git',
credentialsId: 'github-credentials',
maxBranchCount: 10,
branchFilter: 'feature/.*',
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)
- Default Value: Pre-selected branch (optional)
- Parameter Name: The name of the parameter (e.g.,
| Option | Required | Description |
|---|---|---|
name |
Yes | Parameter name |
repositoryUrl |
Yes | Git repository URL (HTTPS or SSH) |
credentialsId |
No | Jenkins credentials ID for private repositories |
maxBranchCount |
Yes | Maximum number of branches to display (1-100) |
branchFilter |
No | Regular expression to filter branch names |
defaultValue |
No | Default selected branch |
description |
No | Parameter description |
| 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 |
- JDK 11 or later
- Maven 3.8+
mvn clean packagemvn hpi:runThis will start a local Jenkins instance at http://localhost:8080/jenkins with the plugin installed.
mvn test- When the build parameter page loads, the plugin fetches remote branches from the configured Git repository
- Branches are retrieved using JGit and sorted by commit date (descending)
- The branch filter regex is applied (if configured)
- The list is truncated to the configured maximum count
- The filtered and sorted list is displayed as a dropdown
- Verify the repository URL is correct
- Check that credentials are configured for private repositories
- Use the "Test Connection" button in the configuration
- Reduce the
maxBranchCountvalue - The first load may be slower as the repository is being cloned temporarily
- 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
Contributions are welcome! Please feel free to submit issues and pull requests.
MIT License - see LICENSE for details.