Uploaded image for project: 'Bamboo Data Center'
  1. Bamboo Data Center
  2. BAM-21253

Checkout branch instead of tag when their names match

XMLWordPrintable

    • Icon: Suggestion Suggestion
    • Resolution: Unresolved
    • None
    • Source Checkout Task
    • None
    • 9
    • Our product teams collect and evaluate feedback from a number of different sources. To learn more about how we use customer feedback in the planning process, check out our new feature policy.

      Problem Definition

      When a branch has the same name of a tag Bamboo checks out the tag instead of the branch HEAD. Here's an example from the "Source Code Checkout" task when we're building a branch named develop that contains a tag develop:

      2021-02-24 10:40:55,854 DEBUG [19-BAM::Default Agent::Agent:pool-39-thread-1] [GitCommandProcessor] Running in /var/atlassian/application-data/bamboo/xml-data/build-dir/BB-TEST0-JOB1: [/usr/bin/git log -1 --encoding=UTF-8 --format=%H HEAD]
      2021-02-24 10:40:55,854 DEBUG [19-BAM::Default Agent::Agent:pool-39-thread-1] [GitCommandBuilder] {GIT_SSH_VARIANT=ssh, SSH_ASKPASS=/bin/echo}
      2021-02-24 10:40:55,875 DEBUG [19-BAM::Default Agent::Agent:pool-39-thread-1] [NativeGitOperationHelper] CacheStats{hitCount=29, missCount=46, loadSuccessCount=31, loadExceptionCount=0, totalLoadTime=18752541500, evictionCount=11}
      2021-02-24 10:40:55,877 DEBUG [19-BAM::Default Agent::Agent:pool-39-thread-1] [GitCommandProcessor] Running in /var/atlassian/application-data/bamboo/xml-data/build-dir/_git-repositories-cache/76d1c9cdafeac85625bd969f9fbbf9c0bab05e42: [/usr/bin/git fetch ssh://010b738c-5856-4d22-b7ff-ec4cc696dc84@127.0.0.1:39831/at/test.git +refs/heads/develop:refs/heads/develop --update-head-ok]
      2021-02-24 10:40:55,878 DEBUG [19-BAM::Default Agent::Agent:pool-39-thread-1] [GitCommandBuilder] {GIT_SSH_VARIANT=ssh, SSH_ASKPASS=/bin/echo, GIT_SSH=/opt/atlassian/bamboo/temp/bamboo-ssh.9900a68e.sh}
      2021-02-24 10:40:56,252 DEBUG [19-BAM::Default Agent::Agent:pool-39-thread-1] [GitCommandProcessor] Running in /var/atlassian/application-data/bamboo/xml-data/build-dir/_git-repositories-cache/76d1c9cdafeac85625bd969f9fbbf9c0bab05e42: [/usr/bin/git log -1 --encoding=UTF-8 --format=%H 1af99a713cffb484a80ccc72c5a5a42a21e92066]
      2021-02-24 10:40:56,253 DEBUG [19-BAM::Default Agent::Agent:pool-39-thread-1] [GitCommandBuilder] {GIT_SSH_VARIANT=ssh, SSH_ASKPASS=/bin/echo}
      2021-02-24 10:40:56,296 DEBUG [19-BAM::Default Agent::Agent:pool-39-thread-1] [GitCommandProcessor] Running in /var/atlassian/application-data/bamboo/xml-data/build-dir/BB-TEST0-JOB1: [/usr/bin/git clone /var/atlassian/application-data/bamboo/xml-data/build-dir/_git-repositories-cache/76d1c9cdafeac85625bd969f9fbbf9c0bab05e42 --shared --no-checkout '-c filter.lfs.smudge=' '-c filter.lfs.required=false' /var/atlassian/application-data/bamboo/xml-data/build-dir/BB-TEST0-JOB1]
      2021-02-24 10:40:56,297 DEBUG [19-BAM::Default Agent::Agent:pool-39-thread-1] [GitCommandBuilder] {GIT_SSH_VARIANT=ssh, SSH_ASKPASS=/bin/echo}
      2021-02-24 10:40:56,925 DEBUG [19-BAM::Default Agent::Agent:pool-39-thread-1] [GitCommandProcessor] Running in /var/atlassian/application-data/bamboo/xml-data/build-dir/BB-TEST0-JOB1: [/usr/bin/git show-ref develop]
      2021-02-24 10:40:56,925 DEBUG [19-BAM::Default Agent::Agent:pool-39-thread-1] [GitCommandBuilder] {GIT_SSH_VARIANT=ssh, SSH_ASKPASS=/bin/echo}
      2021-02-24 10:40:56,958 DEBUG [19-BAM::Default Agent::Agent:pool-39-thread-1] [GitCommandProcessor] --- Full output: ---
      
      2021-02-24 10:40:56,958 DEBUG [19-BAM::Default Agent::Agent:pool-39-thread-1] [GitCommandProcessor] 1af99a713cffb484a80ccc72c5a5a42a21e92066 refs/remotes/origin/develop
      2021-02-24 10:40:56,959 DEBUG [19-BAM::Default Agent::Agent:pool-39-thread-1] [GitCommandProcessor] d74dd3aea3967734e7b4222c9807f0c30e8fed95 refs/tags/develop
      2021-02-24 10:40:56,959 DEBUG [19-BAM::Default Agent::Agent:pool-39-thread-1] [GitCommandProcessor] --- End of output: ---
      
      2021-02-24 10:40:56,960 DEBUG [19-BAM::Default Agent::Agent:pool-39-thread-1] [GitCommandProcessor] Running in /var/atlassian/application-data/bamboo/xml-data/build-dir/BB-TEST0-JOB1: [/usr/bin/git checkout -f develop]
      2021-02-24 10:40:56,961 DEBUG [19-BAM::Default Agent::Agent:pool-39-thread-1] [GitCommandBuilder] {GIT_SSH_VARIANT=ssh, SSH_ASKPASS=/bin/echo, GIT_LFS_SKIP_SMUDGE=1}
      2021-02-24 10:40:57,075 DEBUG [19-BAM::Default Agent::Agent:pool-39-thread-1] [GitCommandProcessor] Running in /var/atlassian/application-data/bamboo/xml-data/build-dir/BB-TEST0-JOB1: [/usr/bin/git remote set-url origin file:///var/atlassian/application-data/bamboo/xml-data/build-dir/_git-repositories-cache/76d1c9cdafeac85625bd969f9fbbf9c0bab05e42]
      2021-02-24 10:40:57,075 DEBUG [19-BAM::Default Agent::Agent:pool-39-thread-1] [GitCommandBuilder] {GIT_SSH_VARIANT=ssh, SSH_ASKPASS=/bin/echo}
      2021-02-24 10:40:57,095 INFO [19-BAM::Default Agent::Agent:pool-39-thread-1] [VcsCheckoutTask] BB-TEST0-JOB1-7: Updated source code to revision: 1af99a713cffb484a80ccc72c5a5a42a21e92066
      
      • The branch is at 1af99a713cffb484a80ccc72c5a5a42a21e92066.
      • Th tag is a couple of commits behind at d74dd3aea3967734e7b4222c9807f0c30e8fed95.

      Despite the fact that Bamboo is reporting the source code was updated to 1af99a713cffb484a80ccc72c5a5a42a21e92066 it was in fact updated to the tag at d74dd3aea3967734e7b4222c9807f0c30e8fed95. This is what I see when I visit the working directory and run git log:

      commit 5d4812893705667d05d111797bb1b292b5649192 (HEAD, tag: develop)
      Author: Bruno Rosa <#####@atlassian.com>
      Date:   Thu Jan 14 10:23:42 2021 +0100
      ...
      

      Suggested Solution

      This happens because the "Source Code Checkout" task is running /usr/bin/git checkout -f develop and git returns the tag instead of the branch. It would be nice if we could force the checkout to happen for the branch when the names match. As you can see from the log snippet above we're running /usr/bin/git show-ref develop before checking out code so we know what reference we could use to get the branch instead of the tag. We could've triggered the following instead:

      git checkout -f refs/remotes/origin/develop
      

      Workaround

      1. Delete the tag.
      2. Access the Bamboo admin > Build resources > Repository settings and delete the repository cache.
      3. Clean up the working directory of the job.
        • The best way to achieve this is to check the "Clean working directory after each build" option inside the job configuration under the Other tab. Trigger at least one build with that option turned ON after the repository cache was removed to force a clean git clone/ checkout.

      This should be enough to prevent Bamboo from checking out the tag and start checking out the branch (HEAD).

      Notes

      Avoid branches and tags with the same name. They are essentially the same thing: pointers to a commit – with the exception that branch pointers advance as we make commits while tags remain static.

              Unassigned Unassigned
              brosa Bruno Rosa
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

                Created:
                Updated: