0
votes

We are using Azure Devops and want to use the variable "$(Rev:r)" in the update assembly task. However we get build errors when using the this variable.

Yaml task:

  - task: update-assembly-info@2
    displayName: 'Update Assembly ...........'
    inputs:
      assemblyInfoFiles: ...........
      company: '...........'
      product: ...........
      copyright: '© $(Assembly.Company) $(Date:yyyy)'
      fileVersionMajor: '$(Date:yyyy)'
      fileVersionMinor: '$(Date:MM)'
      fileVersionBuild: '$(Date:dd)'
      fileVersionRevision: '$(Rev:r)'
      assemblyVersionMajor: '$(Date:yyyy)'
      assemblyVersionMinor: '$(Date:MM)'
      assemblyVersionBuild: '$(Date:dd)'
      assemblyVersionRevision: '$(Rev:r)'

However we get the following error:

##[error]'Allow Scripts to Access OAuth Token' must be enabled when using the $(Rev:r) variable

When we do the exact same steps without using a yaml file but in the GUI in Azure Devops, we can enable the "Allow scripts to access the OAuth token" property and is is working as expected.enter image description here

How can we enable this OAuth token in the yaml file? So we can use this "$(Rev:r)" in the update assembly task in the yaml file?


3

3 Answers

1
votes

Normally it should be done like this

- task: update-assembly-info@2
  inputs:
    assemblyInfoFiles: '**\*AssemblyInfo.*'
  env:
    SYSTEM_ACCESSTOKEN: $(System.AccessToken)

However, this is the issue with the task itself which doesn't support properly mapping System.AccessToken. There is an issue on GitHub

0
votes

It seems you used the following task:

https://marketplace.visualstudio.com/items?itemName=bool.update-assembly-info&targetId=6fb42553-7924-4488-975a-69568174ecbe

You can see this task has been stopped updating since 6/11/2017, and there is no Environment Variables option in this task. To overcome this problem we can use the counter function instead of $(Rev:r). Check the following example:

variables:
  major: 1
  minor: $[counter(variables['major'], 1)]

steps:

- task: update-assembly-info@2
  inputs:
    assemblyInfoFiles: '**\*AssemblyInfo.*'
    company: 'com'
    product: 'pro'
    fileVersionMajor: '$(Date:yyyy)'
    fileVersionMinor: '$(Date:MM)'
    fileVersionBuild: '$(Date:dd)'
    fileVersionRevision: '$(minor)'
    assemblyVersionMajor: '$(Date:yyyy)'
    assemblyVersionMinor: '$(Date:MM)'
    assemblyVersionBuild: '$(Date:dd)'
    assemblyVersionRevision: '$(minor)'
0
votes

Solved my own issue with a workaround.

I use the $(rev:.r) in my build name and use an powershell task to extract the rev-number to a variable.

Complete yaml code for this workaround:

name: $(date:yyyyMMdd)$(rev:.r) #buildnumber format

  - task: InlinePowershell@1                
    displayName: 'Powershell to get the "RevisionNumber"'
    inputs:
      Script: |
        $BuildNumberParts = $($env:BUILD_BUILDNUMBER) -split '\.';
        $RevisionNumber = [int]$BuildNumberParts[$BuildNumberParts.Length-1] ;
        Write-Host "##vso[task.setvariable variable=RevisionNumber]$RevisionNumber";

  - task: update-assembly-info@2
      displayName: 'Update Assembly ...........'
      inputs:
        assemblyInfoFiles: ...........
        company: '...........'
        product: ...........
        copyright: '© $(Assembly.Company) $(Date:yyyy)'
        fileVersionMajor: '$(Date:yyyy)'
        fileVersionMinor: '$(Date:MM)'
        fileVersionBuild: '$(Date:dd)'
        fileVersionRevision: '$(RevisionNumber)'
        assemblyVersionMajor: '$(Date:yyyy)'
        assemblyVersionMinor: '$(Date:MM)'
        assemblyVersionBuild: '$(Date:dd)'
        assemblyVersionRevision: '$(RevisionNumber)'