Reputation: 420
I have a local git repo with the following files:
# .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
#!/usr/bin/env bash
# build.sh
set -ex
git --version
version="$(git describe --always --debug)"
echo "Version: ${version}"
set +ex
and the following 2 remote repos:
$ git remote -v
gitlab [email protected]:user/hello-environments.git (fetch)
gitlab [email protected]:user/hello-environments.git (push)
origin [email protected]:user/hello-world.git (fetch)
origin [email protected]:user/hello-world.git (push)
I have pushed all tags to both remotes:
$ git tag
1.0.0
1.0.1
1.0.2
annotated
light
$ git push origin master --tags
$ git push gitlab master --tags
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.
When the CI pipelines run, on my local instance (GitLab Community Edition 13.0.6), the log shows:
+ 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
but on GitLab.com (GitLab Enterprise Edition 13.1.0-pre eb3529954d4), the log shows:
+ 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
and locally on my Mac:
+ 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
So, even though I'm installing the same git version in the docker container (using apk add git
) it seems that maybe the way that the repo is stored might be different between the EE and CE of GitLab?
How can I get the EE to give me this output:
+ version=1.0.2-4-gb7fb2b5
instead of this output:
+ version=b7fb2b5
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.
diff job-6.txt job-5.txt
3c3
Preparing the "docker" executor
---
Preparing the "docker" executor
5,6d4
< Pulling docker image gitlab/gitlab-runner-helper:x86_64-21cb397c ...
< 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
< Initialized empty Git repository in /builds/craftonix/hello-environments/.git/
< Created fresh repository.
---
> Reinitialized existing Git repository in /builds/craftonix/hello-environments/.git/
16,17c13
< * [new ref] refs/pipelines/158092954 -> refs/pipelines/158092954
< * [new branch] master -> origin/master
---
> * [new ref] refs/pipelines/158095014 -> refs/pipelines/158095014
18a15,16
> Removing build-artifacts/
> 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
< export CI_BUILD_BEFORE_SHA='b7fb2b549e782b5ecef8eebdcf4c6f401bdb9e20'
< export CI_BUILD_ID='603169809'
---
> export CI_BUILD_BEFORE_SHA='0000000000000000000000000000000000000000'
> export CI_BUILD_ID='603178412'
70c68
< export CI_COMMIT_BEFORE_SHA='b7fb2b549e782b5ecef8eebdcf4c6f401bdb9e20'
---
> export CI_COMMIT_BEFORE_SHA='0000000000000000000000000000000000000000'
87c85
< export CI_JOB_ID='603169809'
---
> export CI_JOB_ID='603178412'
93c91
< export CI_JOB_URL='https://gitlab.com/craftonix/hello-environments/-/jobs/603169809'
---
> export CI_JOB_URL='https://gitlab.com/craftonix/hello-environments/-/jobs/603178412'
97,100c95,98
< export CI_PIPELINE_ID='158092954'
< export CI_PIPELINE_IID='16'
< export CI_PIPELINE_SOURCE='push'
< export CI_PIPELINE_URL='https://gitlab.com/craftonix/hello-environments/-/pipelines/158092954'
---
> export CI_PIPELINE_ID='158095014'
> export CI_PIPELINE_IID='17'
> export CI_PIPELINE_SOURCE='web'
> export CI_PIPELINE_URL='https://gitlab.com/craftonix/hello-environments/-/pipelines/158095014'
158,162c156,163
< Building with GitLab-CI. Build number: 16
< + version=6e97a0f
< + [[ -z 16 ]]
< + echo 'Building with GitLab-CI. Build number: 16'
< + version_string=6e97a0f
---
> finished search at dda25569a70226f4782fd2203f0fa5d9f94713e9
> annotated 5 1.0.2
> traversed 6 commits
> + version=1.0.2-5-g6e97a0f
> + [[ -z 17 ]]
> + echo 'Building with GitLab-CI. Build number: 17'
> Building with GitLab-CI. Build number: 17
> + version_string=1.0.2-5-g6e97a0f
164c165
< + build_number=16
---
> + build_number=17
168,169c169,170
< + echo 'Version : 6e97a0f'
< + echo 'Build : 16'
---
> + echo 'Version : 1.0.2-5-g6e97a0f'
> + 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
< Uploading artifacts to coordinator... ok id=603169809 responseStatus=201 Created token=crsXNrVb
Job succeeded
---
> Uploading artifacts to coordinator... ok id=603178412 responseStatus=201 Created token=p6-GLXLn
Job succeeded
$ 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
I don't know how to find the version of the current shared runner.
However, the same runner version 13.0.1 gave 2 different results in build 16 and 17.
Upvotes: 2
Views: 2088