## [错误]在以下环境变量中找不到版本号数据:BUILD_BUILDNUMBER

时间:2019-09-05 00:49:02

标签: azure-devops nuget azure-pipelines azure-pipelines-build-task

我正在使用以下yaml生成我的NuGet pkg。我想为包裹添加唯一的ID和日期。但我不断收到错误消息,说无法在以下环境变量中找到版本号数据:BUILD_BUILDNUMBER

  

## [错误]在以下环境变量中找不到版本号数据:BUILD_BUILDNUMBER。变量的值   应该包含带有或为正整数的子字符串。

我尝试使用名称:$(Build.DefinitionName)-$(date:yyyyMMdd)$(rev:.r)#需要byBuildNumber verisonScheme nuget pack使用它。

还尝试在yaml文件中将BUILD_BUILDNUMBER设置为变量。

# ASP.NET Core
# Build and test ASP.NET Core projects targeting .NET Core.
# Add steps that run tests, create a NuGet package, deploy, and more:
# https://docs.microsoft.com/azure/devops/pipelines/languages/dotnet-core

name: $(Build.DefinitionName)-$(date:yyyyMMdd)$(rev:.r) # need this for byBuildNumber verisonScheme nuget pack
# the build will trigger on any changes to the master branch
trigger:
- master

# the build will run on a Microsoft hosted agent, using the lastest Windows VM Image
pool:
  vmImage: 'windows-latest'

# these variables are available throughout the build file
# just the build configuration is defined, in this case we are building Release packages
variables:
  buildConfiguration: 'Release'


#The build has 3 seperate tasks run under 1 step
steps:
# The first task is the dotnet command build, pointing to our csproj file
- task: DotNetCoreCLI@2
  displayName: 'dotnet build'
  inputs:
    command: 'build'
    arguments: '--configuration $(buildConfiguration)'
    projects: 'src/Repository.sln'

# The second task is dotnet pack command again pointing to the csproj file
# The nobuild means the project will not be compiled before running pack, because its already built in above step
- task: DotNetCoreCLI@2
  displayName: "dotnet pack"
  inputs:
    command: 'pack'
    arguments: '--configuration $(buildConfiguration)'
    packagesToPack: 'src/Common.Core/Common.Core.csproj'
    nobuild: true
    includeSymbols: true
    versioningScheme: 'byBuildNumber'


# The last task is a nuget command, nuget push
# This will push any .nupkg files to the 'Nuget' artifact feed
# allowPackageConflicts allows us to build the same version and not throw an error when trying to push
# instead it just ingores the latest package unless the version changes
- task: NuGetCommand@2
  displayName: 'nuget push'
  inputs:
    command: 'push'
    feedsToUse: 'select'
    packagesToPush: '$(Build.ArtifactStagingDirectory)/**/*.nupkg;!$(Build.ArtifactStagingDirectory)/**/*.symbols.nupkg'
    nuGetFeedType: 'internal'
    publishVstsFeed: 'MyNuget'
    allowPackageConflicts: true


我希望它会生成具有正确版本号的nuget,而不会导致nuget pack步骤失败。

1 个答案:

答案 0 :(得分:0)

当您选择NuGet软件包的版本将类似于内部版本号时,您不能将此值try { ApplicationInfo ai = getPackageManager().getApplicationInfo(activity.getPackageName(), PackageManager.GET_META_DATA); Bundle bundle = ai.metaData; String myApiKey = bundle.getString("my_api_key"); } catch (NameNotFoundException e) { Log.e(TAG, "Failed to load meta-data, NameNotFound: " + e.getMessage()); } catch (NullPointerException e) { Log.e(TAG, "Failed to load meta-data, NullPointer: " + e.getMessage()); } 赋予内部版本号。

应采用以下格式:

$(Build.DefinitionName)-$(date:yyyyMMdd)$(rev:.r)

您可以在经典编辑器中看到此信息:

enter image description here

您可以在docs中找到更多信息:

对于 byPrereleaseNumber ,版本将设置为您为主要,次要和补丁选择的任何版本,以及日期和时间,格式为yyyymmdd-hhmmss。

对于 byEnvVar ,该版本将设置为任何环境变量,例如您提供的是MyVersion(没有$,只有环境变量名称)。确保将环境变量设置为正确的SemVer,例如1.2.3或1.2.3-beta1。

对于 byBuildNumber ,版本将设置为内部版本号,请确保您的内部版本号是正确的SemVer,例如1.0。$(Rev:r)。如果选择byBuildNumber,则该任务将提取一个点缀的版本1.2.3.4,并仅使用该版本,并删除所有标签。要按原样使用内部版本号,您应该如上所述使用byEnvVar,并将环境变量设置为BUILD_BUILDNUMBER。