Skip to content

Dockerfile giving null reference exception? #1441

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
yamikuronue opened this issue Jul 6, 2018 · 8 comments
Closed

Dockerfile giving null reference exception? #1441

yamikuronue opened this issue Jul 6, 2018 · 8 comments
Labels

Comments

@yamikuronue
Copy link

yamikuronue commented Jul 6, 2018

I am attempting to capture the correct image number so it can be baked into Packer when building my AMIs. I am using the following partial build.sh to capture that information in an environment variable so I can pass it along to Packer:

IMAGE_VERSION=$(docker run --rm -u $(id -u):$(id -g) -v $(pwd):/repo gittools/gitversion:v4.0.0-beta.12 /showvariable SemVer)


echo "Building images version $IMAGE_VERSION"

I am running this on a linux agent in teamcity (the current teamcity plugin requires Powershell apparently). I am building on a branch in a repo, it's a fairly new repo so there's nothing weird going on. I am getting the following output:

[16:35:39][Step 1/1] Building images version INFO [07/05/18 20:35:37:21] Working directory: /repo
[16:35:39][Step 1/1] INFO [07/05/18 20:35:37:22] IsDynamicGitRepository: False
[16:35:39][Step 1/1] INFO [07/05/18 20:35:37:25] Returning Project Root from DotGitDirectory: /repo/.git - /repo
[16:35:39][Step 1/1] INFO [07/05/18 20:35:37:25] Running on Mono.
[16:35:39][Step 1/1] INFO [07/05/18 20:35:37:26] IsDynamicGitRepository: False
[16:35:39][Step 1/1] INFO [07/05/18 20:35:37:26] Returning Project Root from DotGitDirectory: /repo/.git - /repo
[16:35:39][Step 1/1] INFO [07/05/18 20:35:37:26] Project root is: /repo
[16:35:39][Step 1/1] INFO [07/05/18 20:35:37:26] DotGit directory is: /repo/.git
[16:35:39][Step 1/1] INFO [07/05/18 20:35:37:27] IsDynamicGitRepository: False
[16:35:39][Step 1/1] INFO [07/05/18 20:35:37:27] Returning Project Root from DotGitDirectory: /repo/.git - /repo
[16:35:39][Step 1/1] INFO [07/05/18 20:35:37:30] Begin: Loading version variables from disk cache
[16:35:39][Step 1/1]   INFO [07/05/18 20:35:37:31] Cache file /repo/.git/gitversion_cache/A2990A7006B056135D53E257F3260AEE6BE8A13C.yml not found.
[16:35:39][Step 1/1] INFO [07/05/18 20:35:37:31] End: Loading version variables from disk cache (Took: 1.44ms)
[16:35:39][Step 1/1] INFO [07/05/18 20:35:37:31] IsDynamicGitRepository: False
[16:35:39][Step 1/1] INFO [07/05/18 20:35:37:31] Returning Project Root from DotGitDirectory: /repo/.git - /repo
[16:35:39][Step 1/1] INFO [07/05/18 20:35:37:44] Using latest commit on specified branch
[16:35:39][Step 1/1] INFO [07/05/18 20:35:37:45] Begin: Attempting to inherit branch configuration from parent branch
[16:35:39][Step 1/1] INFO [07/05/18 20:35:37:45] End: Attempting to inherit branch configuration from parent branch (Took: 0.22ms)
[16:35:39][Step 1/1] ERROR [07/05/18 20:35:37:45] An unexpected error occurred:
[16:35:39][Step 1/1] System.NullReferenceException: Object reference not set to an instance of an object
[16:35:39][Step 1/1]   at GitVersion.BranchConfigurationCalculator.InheritBranchConfiguration (GitVersion.GitVersionContext context, LibGit2Sharp.Branch targetBranch, GitVersion.BranchConfig branchConfiguration, System.Collections.Generic.IList`1[T] excludedInheritBranches) [0x00035] in <248b18560e0a4c7a85ffc14b47d49ab1>:0 
[16:35:39][Step 1/1]   at GitVersion.BranchConfigurationCalculator.GetBranchConfiguration (GitVersion.GitVersionContext context, LibGit2Sharp.Branch targetBranch, System.Collections.Generic.IList`1[T] excludedInheritBranches) [0x000f0] in <248b18560e0a4c7a85ffc14b47d49ab1>:0 
[16:35:39][Step 1/1]   at GitVersion.GitVersionContext.CalculateEffectiveConfiguration () [0x00007] in <248b18560e0a4c7a85ffc14b47d49ab1>:0 
[16:35:39][Step 1/1]   at GitVersion.GitVersionContext..ctor (LibGit2Sharp.IRepository repository, LibGit2Sharp.Branch currentBranch, GitVersion.Config configuration, System.Boolean onlyEvaluateTrackedBranches, System.String commitId) [0x00121] in <248b18560e0a4c7a85ffc14b47d49ab1>:0 
[16:35:39][Step 1/1]   at GitVersion.GitVersionContext..ctor (LibGit2Sharp.IRepository repository, GitVersion.Config configuration, System.Boolean isForTrackingBranchOnly, System.String commitId) [0x00008] in <248b18560e0a4c7a85ffc14b47d49ab1>:0 
[16:35:39][Step 1/1]   at GitVersion.ExecuteCore+<>c__DisplayClass6_0.<ExecuteInternal>b__0 (LibGit2Sharp.IRepository repo) [0x00000] in <248b18560e0a4c7a85ffc14b47d49ab1>:0 
[16:35:39][Step 1/1]   at GitVersion.GitPreparer.WithRepository[TResult] (System.Func`2[T,TResult] action) [0x0000c] in <248b18560e0a4c7a85ffc14b47d49ab1>:0 
[16:35:39][Step 1/1]   at GitVersion.ExecuteCore.ExecuteInternal (System.String targetBranch, System.String commitId, GitVersion.GitPreparer gitPreparer, GitVersion.IBuildServer buildServer, GitVersion.Config overrideConfig) [0x0002d] in <248b18560e0a4c7a85ffc14b47d49ab1>:0 
[16:35:39][Step 1/1]   at GitVersion.ExecuteCore.ExecuteGitVersion (System.String targetUrl, System.String dynamicRepositoryLocation, GitVersion.Authentication authentication, System.String targetBranch, System.Boolean noFetch, System.String workingDirectory, System.String commitId, GitVersion.Config overrideConfig, System.Boolean noCache) [0x000df] in <248b18560e0a4c7a85ffc14b47d49ab1>:0 
[16:35:39][Step 1/1]   at GitVersion.SpecifiedArgumentRunner.Run (GitVersion.Arguments arguments, GitVersion.Helpers.IFileSystem fileSystem) [0x0007c] in <248b18560e0a4c7a85ffc14b47d49ab1>:0 
[16:35:39][Step 1/1]   at GitVersion.Program.VerifyArgumentsAndRun () [0x00182] in <248b18560e0a4c7a85ffc14b47d49ab1>:0 
[16:35:39][Step 1/1] INFO [07/05/18 20:35:37:45] 
[16:35:39][Step 1/1] INFO [07/05/18 20:35:37:45] Attempting to show the current git graph (please include in issue): 
[16:35:39][Step 1/1] INFO [07/05/18 20:35:37:45] Showing max of 100 commits
[16:35:39][Step 1/1] INFO [07/05/18 20:35:38:39] ERROR: error: object directory /opt/teamcity-buildagent/system/git/git-B2CDEA8F.git/objects does not exist; check .git/objects/info/alternates.
[16:35:39][Step 1/1] ERROR: error: refs/heads/feature/cicd does not point to a valid object!
[16:35:39][Step 1/1] ERROR: error: refs/heads/master does not point to a valid object!
[16:35:39][Step 1/1] ERROR: error: refs/remotes/origin/feature/cicd does not point to a valid object!
[16:35:39][Step 1/1] ERROR: error: refs/remotes/origin/master does not point to a valid object!
[16:35:39][Step 1/1] ERROR: error: refs/tags/1.3.0 does not point to a valid object!
[16:35:39][Step 1/1] ERROR: fatal: bad object HEAD

(the capture of the output may be wrong too, but at the moment I'm mostly concerned with the error it's throwing).

What have I done wrong here? I have set it to fetch all heads, so shouldn't it have all the info it needs?

@dazinator
Copy link
Member

Can you try adding a global.json to your solution and pin the sdk version to 2.0.0. We havent merged support for dotnet sdk > 2.0.0 yet and i have a feeling perhaps the base docker image has now moved on to having dotnet sdk 2.1 installed despite being called 2.0

@yamikuronue
Copy link
Author

I can do that, but I'm not certain where to put it, since I don't have a solution folder or anything. I'm using this to version the AMIs I'm building using Packer. Do I put it at the root of the repository?

@dazinator
Copy link
Member

dazinator commented Aug 29, 2018

@yamikuronue ignore me. I was confusing the issue, assuming it was a build issue but its nothing to do with dotnet build. You are just mounting the repo into the container and calling gitversion cli against it. The stack trace looks like gitversion has a problem inspecting the repo when looking at the branch for some reason. If you are using team city have you read the gitversion docs team city section which mentions about checkout mode (i.e server / agent) - I wonder if your repo isn't being initialised by team city in a state that gitversion can work with (complete guess)

@yamikuronue
Copy link
Author

Yeah, I set it to "fetch all heads" which I would assume gets the full repo state (using the optional property teamcity.git.fetchAllHeads = true). It's also set to checkout builds on the agent -- is that better or worse for this than the server? I would assume the agent is the one running the dockerfile, but I'm new to teamcity, maybe it's counter-intuitive?

@yamikuronue
Copy link
Author

I do spy /usr/bin/git config core.sparseCheckout true in the build output -- could that be the issue? but I'm not sure how to disable that, I'm digging now. It seems like if I'm forcing all heads the branch data should be there, regardless of the files checked out, right?

@stale
Copy link

stale bot commented Jun 29, 2019

This issue has been automatically marked as stale because it has not had recent activity. After 30 days from now, it will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Jun 29, 2019
@oliverroer
Copy link

Can you check your Version Control Settings on TeamCity?
Is Use mirrors enabled on your VCS root?

When enabling User mirrors, this uses a Git feature called "alternates" where some of the Git objects are stored elsewhere on the host, in order to save space and make things run faster. (I'm not particularly knowledgeable on this particular feature - please correct me if I'm wrong here)

Anyways, we've had issues with this, when mounting the checkout directory into a container with GitVersion.
The problem then, is that the container doesn't have access to all the file GitVersion needs, because some of the files are actually stored elsewhere on the host system.

The solution is then to disable Use mirrors.

I wonder if it would be possible for GitVersion to identify and report this issue when it happens. The current error messages are not very helpful. I have had quite a few colleagues run into this issue, and spending quite a lot of time scratching their heads.

For comparison, here's how it looks on our agents, when mirrors is in use and the build starts to break:

INFO [07/23/19 11:17:33:31] Working directory: /repo/build
INFO [07/23/19 11:17:33:32] IsDynamicGitRepository: False
INFO [07/23/19 11:17:33:34] Returning Project Root from DotGitDirectory: /repo/.git - /repo
INFO [07/23/19 11:17:33:34] Running on Windows.
INFO [07/23/19 11:17:33:34] Applicable build agent found: 'TeamCity'.
INFO [07/23/19 11:17:33:35] Branch from build environment: refs/heads/master
INFO [07/23/19 11:17:33:35] Begin: Normalizing git directory for branch 'refs/heads/master'
  INFO [07/23/19 11:17:33:39] End: Normalizing git directory for branch 'refs/heads/master' (Took: 47.31ms)
  ERROR [07/23/19 11:17:33:56] An unexpected error occurred:
System.NullReferenceException: Object reference not set to an instance of an object.
   at GitVersion.GitRepositoryHelper.NormalizeGitDirectory(String gitDirectory, AuthenticationInfo authentication, Boolean noFetch, String currentBranch) in /home/vsts/work/1/s/src/GitVersionCore/Helpers/GitRepositoryHelper.cs:line 16
   at GitVersion.GitPreparer.Initialise(Boolean normaliseGitDirectory, String currentBranch, Boolean shouldCleanUpRemotes) in /home/vsts/work/1/s/src/GitVersionCore/GitPreparer.cs:line 63
   at GitVersion.ExecuteCore.ExecuteGitVersion(String targetUrl, String dynamicRepositoryLocation, Authentication authentication, String targetBranch, Boolean noFetch, String workingDirectory, String commitId, Config overrideConfig, Boolean noCache) in /home/vsts/work/1/s/src/GitVersionCore/ExecuteCore.cs:line 28
   at GitVersion.SpecifiedArgumentRunner.Run(Arguments arguments, IFileSystem fileSystem) in /home/vsts/work/1/s/src/GitVersionExe/SpecifiedArgumentRunner.cs:line 28
   at GitVersion.Program.VerifyArgumentsAndRun() in /home/vsts/work/1/s/src/GitVersionExe/Program.cs:line 113
  INFO [07/23/19 11:17:33:57] 
  INFO [07/23/19 11:17:33:57] Attempting to show the current git graph (please include in issue): 
  INFO [07/23/19 11:17:33:57] Showing max of 100 commits

This is using version 5.0 of GitVersion in Docker.

@stale
Copy link

stale bot commented Oct 21, 2019

This issue has been automatically marked as stale because it has not had recent activity. After 30 days from now, it will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Oct 21, 2019
@stale stale bot closed this as completed Nov 20, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants