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

BRANCH_NAME undefined for non-multibranch jobs

    Details

    • Type: Bug
    • Status: Closed (View Workflow)
    • Priority: Minor
    • Resolution: Not A Defect
    • Component/s: scm-api-plugin
    • Labels:
      None
    • Environment:
      LTS 2.46.3
    • Similar Issues:

      Description

      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]

        Attachments

          Activity

          Hide
          markewaite 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.

          Show
          markewaite 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.
          Hide
          krachynski Ken Rachynski added a comment -

          That works for me, thank you.

          tang^

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

            People

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

              Dates

              • Created:
                Updated:
                Resolved: