Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-45090

BRANCH_NAME undefined for non-multibranch jobs

    • Icon: Bug Bug
    • Resolution: Not A Defect
    • Icon: Minor Minor
    • scm-api-plugin
    • None
    • LTS 2.46.3

      I have a project that now needs to know what branch it's currently operating under when it builds. The nature of our build process prevents us from using multibranch pipelines or similar freestyle jobs. I have discovered the related issue JENKINS-43104 which describes the behaviour I'm experiencing. BRANCH_NAME is not set at all for non-multibranch jobs.

      I have a sample Maven project that tries to commit changes from the build back to the repository but fails due to missing branch information. This can be found at https://github.com/kenrachynski/pipeline-branch-error.git

      Running the maven build in a freestyle job exhibits the exact same behaviour. The error:
      [ERROR] Failed to execute goal org.apache.maven.plugins:maven-scm-plugin:1.9.5:checkin (04-commit) on project pipeline-branch-error: Cannot run checkin command : Exception while executing SCM command. Detecting the current branch failed: fatal: ref HEAD is not a symbolic ref -> [Help 1]

          [JENKINS-45090] BRANCH_NAME undefined for non-multibranch jobs

          Mark Waite added a comment -

          If you're using the git plugin, then there is an "Additional Behaviour" called "Check out to specific local branch". If that is configured with an empty string, or with "**", then the plugin will create a local branch based on the name of the remote branch.

          The default is to checkout a "detached HEAD", but with "Check out to specific local branch", it uses a named branch for the checkout instead of a detached HEAD.

          Mark Waite added a comment - If you're using the git plugin, then there is an "Additional Behaviour" called "Check out to specific local branch". If that is configured with an empty string, or with "**", then the plugin will create a local branch based on the name of the remote branch. The default is to checkout a "detached HEAD", but with "Check out to specific local branch", it uses a named branch for the checkout instead of a detached HEAD.

          Ken Rachynski added a comment -

          That works for me, thank you.

          tang^

          Ken Rachynski added a comment - That works for me, thank you. tang^

            Unassigned Unassigned
            krachynski Ken Rachynski
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: