Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

To obtain the name of the local Git branch using the Jenkins Git plugin, follow these steps:

  1. In your Jenkins job configuration, go to the Source Code Management section and select Git.
  2. Enter the Git repository URL and credentials.
  3. In the Branches to build field, specify the Git branch you want to build. You can use a specific branch name, a branch pattern, or a Git commit ID.
  4. Click the Advanced button to see more options.
  5. In the Name field under Local subdirectory for repo (optional), enter the name of the local directory to store the Git repository. You can use a variable such as ${BRANCH_NAME} to dynamically name the directory based on the selected branch.
  6. Save your Jenkins job configuration.

Once you have configured your Jenkins job with the Git plugin, Jenkins will automatically clone the Git repository to the local directory and checkout the specified branch. To obtain the name of the local Git branch during the build, you can use the ${BRANCH_NAME} environment variable. This variable will contain the name of the Git branch that was checked out.