Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.1k views
in Technique[技术] by (71.8m points)

git - Build.SourceVersion is blank in VSO vNext Build

I am using the new scriptable build features in Visual Studio Online (not the XAML build definitions), and I am trying to have the build version number include the latest Git Commit ID of the target repository using the Build Number Format.

I am using the following build number format:

$(MajorVersion).$(MinorVersion).$(BuildId).$(SourceVersion)

Which results in a generated version number of 1.0.1234. - i.e. the SourceVersion value is blank, which causes an error in VSO when queueing a build. I have also tried qualifying the variable by prefixing it with Build. with the same result. To test, I have changed the build number to the following format:

$(MajorVersion).$(MinorVersion).$(BuildId).$(SourceBranch)

This correctly results in a value of 1.0.1234.refs_heads_master

I have been using the Predefined Variables reference and Build.SourceVersion is listed as a Global Variable.

Am I doing something wrong, have I encountered a bug or is this by design and not available at the time the build is queued? If this is by design, is there any way to automatically include the short Git Commit ID in the Build Number Format?

This is where I set the build number format in VSO: This is where I set the build number format in VSO

This is the error I see when I don't explicitly specify a Git CommitId:

400: The build number format string $(MajorVersion).$(MinorVersion).$(BuildId).$(SourceVersion) generated a build number 0.1.1. which contains invalid character(s), is too long, or ends with '.'. The maximum length of a build number is 255 characters. Characters which are not allowed include '"', '/', ':', '<', '>', '', '|', '?', '@', and '*'.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I was able to use $(Build.SourceVersion), but only when builds were triggered automatically on commit (on Continuous integration). It turns out to be empty only if I queue it manually:

Build queue screenshot

I'm using the following Build number format:

$(BuildDefinitionName)_$(date:yyyyMMdd)_$(Build.BuildId).$(Build.SourceVersion)$(rev:.r)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

56.8k users

...