在 azure 管道中获取内部版本号

时间:2021-05-26 11:30:46

标签: azure-pipelines

variables:
  ${{ if eq(variables['Build.SourceBranchName'], 'master') }}:
    buildConfiguration: 'Release'
    tag: ''
    packVersionSuffix: ''
    # versionSuffix seems to be a special magic name, so setting it makes stuff break.
    
  ${{ if ne(variables['Build.SourceBranchName'], 'master') }}:
    buildConfiguration: 'Debug'
    tag: ${{ format('-{0}.{1}', variables['Build.SourceBranchName'], variables['Build.BuildId']) }}
    packVersionSuffix: ${{ format('{0}.{1}-{2}', variables['Build.SourceBranchName'], variables['Build.BuildId'], 'two' ) }}

steps:

- script: echo "packVersionSuffix is $(packVersionSuffix)"

{1}位中代入后始终为空串,即variables['Build.BuildId']的值始终为空串。

我怎样才能获得实际的内部版本号?

2 个答案:

答案 0 :(得分:1)

我有点担心您将无法在此处获得 BuildId,因为这在表达式中不可用:

enter image description here

因此,您需要在 powershell 步骤中构建 packVersionSuffix,然后通过日志记录命令将其分配给 Azure Devops 变量。

答案 1 :(得分:0)

Azure 管道的典型情况是:它不起作用。

这里有一些东西...

- task: PowerShell@2
  displayName: 'Set versionSuffix (when not master)'
  condition: ne(variables['Build.SourceBranchName'], 'master')
  inputs:
    targetType: 'inline'
    script: |
         $packVersionSuffix = "$(Build.SourceBranchName).$(Build.BuildId)"
         echo "packVersionSuffix is: ${packVersionSuffix}"
         # This sets the variable in the whole pipeline
         echo "##vso[task.setvariable variable=packVersionSuffix]$packVersionSuffix"

- task: PowerShell@2
  displayName: 'Set versionSuffix (when master)'
  condition: eq(variables['Build.SourceBranchName'], 'master')
  inputs:
    targetType: 'inline'
    script: |
          $packVersionSuffix = ""
          echo "##vso[task.setvariable variable=packVersionSuffix]$packVersionSuffix"

- task: DotNetCoreCLI@2
  displayName: 'dotnet pack Project'
  inputs:
    command: 'pack'
    packagesToPack: 'Folder\Project.csproj'
    includesymbols: true
    includesource: true
    nobuild: true
    buildProperties: 'VersionSuffix="$(packVersionSuffix)"'
    versionSuffix: '$(packVersionSuffix'
    outputDir: '$(Build.ArtifactStagingDirectory)'
    arguments: '--version-suffix $(packVersionSuffix)'