title: Why is the output of 'git describe' different from one build to another?
body: <p>I have a local git repo with the following files:</p>
  <pre class="lang-yaml prettyprint-override"><code># .gitlab-ci.yml
  
  image: alpine:latest
  
  before_script:
    - apk update
    - apk upgrade
    - apk add bash
    - apk add git
  
  qa_build:
    environment:
      name: qa
    tags:
      - docker
    stage: build
    script:
      - ./build.sh
  </code></pre>
  <pre class="lang-bash prettyprint-override"><code>#!/usr/bin/env bash
  
  # build.sh
  
  set -ex
  
  git --version
  
  version=&quot;$(git describe --always --debug)&quot;
  
  echo &quot;Version: ${version}&quot;
  
  set +ex
  
  </code></pre>
  <p>and the following 2 remote repos:</p>
  <pre><code>$ git remote -v
  
  gitlab  git@gitlab.com:user/hello-environments.git (fetch)
  gitlab  git@gitlab.com:user/hello-environments.git (push)
  origin  git@192.168.50.10:user/hello-world.git (fetch)
  origin  git@192.168.50.10:user/hello-world.git (push)
  
  </code></pre>
  <p>I have pushed all tags to both remotes:</p>
  <pre><code>$ git tag
  
  1.0.0
  1.0.1
  1.0.2
  annotated
  light
  
  $ git push origin master --tags
  $ git push gitlab master --tags
  </code></pre>
  <p>and I can see all 5 tags in the web interface of both the GitLab.com EE and my local instance, which is GitLab CE.</p>
  <p>When the CI pipelines run, on my local instance (GitLab Community Edition 13.0.6), the log shows:</p>
  <pre><code>+ git --version
   git version 2.26.2
   ++ git describe --always --debug
   describe HEAD
   No exact match on refs or tags, searching to describe
   finished search at dda25569a70226f4782fd2203f0fa5d9f94713e9
    annotated          4 1.0.2
   traversed 5 commits
   + version=1.0.2-4-gb7fb2b5
  </code></pre>
  <p>but on GitLab.com (GitLab Enterprise Edition 13.1.0-pre eb3529954d4), the log shows:</p>
  <pre><code>+ git --version
   git version 2.26.2
   ++ git describe --always --debug
   describe HEAD
   No exact match on refs or tags, searching to describe
   + version=b7fb2b5
  </code></pre>
  <p>and locally on my Mac:</p>
  <pre><code>+ git --version
  git version 2.21.1 (Apple Git-122.3)
  
  + git describe --always --debug
  describe HEAD
  No exact match on refs or tags, searching to describe
  finished search at dda25569a70226f4782fd2203f0fa5d9f94713e9
   annotated          4 1.0.2
  traversed 5 commits
  1.0.2-4-gb7fb2b5
  </code></pre>
  <p>So, even though I'm installing the same git version in the docker container (using <code>apk add git</code>) it seems that maybe the way that the repo is stored might be different between the EE and CE of GitLab?</p>
  <p>How can I get the EE to give me this output:</p>
  <pre><code>+ version=1.0.2-4-gb7fb2b5
  </code></pre>
  <p>instead of this output:</p>
  <pre><code>+ version=b7fb2b5
  </code></pre>
  <h1>Update July 6, 2020</h1>
  <p>Sorry, after further investigation, I found out that CE and EE probably have nothing to do with the difference. I tried with a shared runner vs my own local runner, and still I could not tell when 'git describe' would give a different result. However, I did notice a difference between 2 builds on the same runner, same pipeline, re-building the same job. So I'm pasting it here in case someone is able to pinpoint the root cause. Build 16 (job-6.txt) has the wrong output. Build 17 (job-5.txt) has the correct output.</p>
  <pre><code>diff job-6.txt job-5.txt
  3c3
  Preparing the &quot;docker&quot; executor
  ---
  Preparing the &quot;docker&quot; executor
  5,6d4
  &lt; Pulling docker image gitlab/gitlab-runner-helper:x86_64-21cb397c ...
  &lt; Using docker image sha256:df1ff93a0e2db810c4900db1681af6327ba8885790dec8aba3226dffd24288d1 for gitlab/gitlab-runner-helper:x86_64-21cb397c ...
  9c7
  Preparing environment
  ---
  Preparing environment
  11c9
  Getting source from Git repository
  ---
  Getting source from Git repository
  13,14c11
  &lt; Initialized empty Git repository in /builds/craftonix/hello-environments/.git/
  &lt; Created fresh repository.
  ---
  &gt; Reinitialized existing Git repository in /builds/craftonix/hello-environments/.git/
  16,17c13
  &lt;  * [new ref]         refs/pipelines/158092954 -&gt; refs/pipelines/158092954
  &lt;  * [new branch]      master                   -&gt; origin/master
  ---
  &gt;  * [new ref]         refs/pipelines/158095014 -&gt; refs/pipelines/158095014
  18a15,16
  &gt; Removing build-artifacts/
  &gt; Removing deploy/
  21,23c19,21
  Restoring cache
  Downloading artifacts
  Running before_script and script
  ---
  Restoring cache
  Downloading artifacts
  Running before_script and script
  62,63c60,61
  &lt; export CI_BUILD_BEFORE_SHA='b7fb2b549e782b5ecef8eebdcf4c6f401bdb9e20'
  &lt; export CI_BUILD_ID='603169809'
  ---
  &gt; export CI_BUILD_BEFORE_SHA='0000000000000000000000000000000000000000'
  &gt; export CI_BUILD_ID='603178412'
  70c68
  &lt; export CI_COMMIT_BEFORE_SHA='b7fb2b549e782b5ecef8eebdcf4c6f401bdb9e20'
  ---
  &gt; export CI_COMMIT_BEFORE_SHA='0000000000000000000000000000000000000000'
  87c85
  &lt; export CI_JOB_ID='603169809'
  ---
  &gt; export CI_JOB_ID='603178412'
  93c91
  &lt; export CI_JOB_URL='https://gitlab.com/craftonix/hello-environments/-/jobs/603169809'
  ---
  &gt; export CI_JOB_URL='https://gitlab.com/craftonix/hello-environments/-/jobs/603178412'
  97,100c95,98
  &lt; export CI_PIPELINE_ID='158092954'
  &lt; export CI_PIPELINE_IID='16'
  &lt; export CI_PIPELINE_SOURCE='push'
  &lt; export CI_PIPELINE_URL='https://gitlab.com/craftonix/hello-environments/-/pipelines/158092954'
  ---
  &gt; export CI_PIPELINE_ID='158095014'
  &gt; export CI_PIPELINE_IID='17'
  &gt; export CI_PIPELINE_SOURCE='web'
  &gt; export CI_PIPELINE_URL='https://gitlab.com/craftonix/hello-environments/-/pipelines/158095014'
  158,162c156,163
  &lt; Building with GitLab-CI. Build number: 16
  &lt; + version=6e97a0f
  &lt; + [[ -z 16 ]]
  &lt; + echo 'Building with GitLab-CI. Build number: 16'
  &lt; + version_string=6e97a0f
  ---
  &gt; finished search at dda25569a70226f4782fd2203f0fa5d9f94713e9
  &gt;  annotated          5 1.0.2
  &gt; traversed 6 commits
  &gt; + version=1.0.2-5-g6e97a0f
  &gt; + [[ -z 17 ]]
  &gt; + echo 'Building with GitLab-CI. Build number: 17'
  &gt; Building with GitLab-CI. Build number: 17
  &gt; + version_string=1.0.2-5-g6e97a0f
  164c165
  &lt; + build_number=16
  ---
  &gt; + build_number=17
  168,169c169,170
  &lt; + echo 'Version    : 6e97a0f'
  &lt; + echo 'Build      : 16'
  ---
  &gt; + echo 'Version    : 1.0.2-5-g6e97a0f'
  &gt; + echo 'Build      : 17'
  172,174c173,175
  Running after_script
  Saving cache
  Uploading artifacts for successful job
  ---
  Running after_script
  Saving cache
  Uploading artifacts for successful job
  177,178c178,179
  &lt; Uploading artifacts to coordinator... ok            id=603169809 responseStatus=201 Created token=crsXNrVb
  Job succeeded
  ---
  &gt; Uploading artifacts to coordinator... ok            id=603178412 responseStatus=201 Created token=p6-GLXLn
  Job succeeded
  </code></pre>
  <h1>Update July 7, 2020</h1>
  <h2>gitlab-runner versions</h2>
  <h3>macOS runner</h3>
  <pre><code>$ gitlab-runner -v
  Version:      13.0.1
  Git revision: 21cb397c
  Git branch:   13-0-stable
  GO version:   go1.14.3
  Built:        2020-06-08T10:10:54+01:00
  OS/Arch:      darwin/amd64
  </code></pre>
  <h3>GitLab.com shared runner</h3>
  <p>I don't know how to find the version of the <em>current</em> shared runner.</p>
  <p>However, the same runner version 13.0.1 gave 2 different results in build 16 and 17.</p>