9

I have requirement that my build is generating abc.msi file through Private build agent.Now I have added the Powershell task to rename the abc.msi with abc_3.0.0$(Rev:r).msi but The Powershell task is failing.Please help me out how to achieve this.I would like to have the build name format like abc_3.0.0.1 ,abc_3.0.0.2,abc_3.0.0.3 ...and so on.It should keep increase the value of $(Rev:r) as the builds are getting increased.

The Powershell command which I am running is:

Rename-Item -Path "C:\Softwares\vsts-agent-win-x86-2.147.1\_work\1\s\src\abcSetup\Release\abc.msi" -NewName "C:\Softwares\vsts-agent-win-x86-2.147.1\_work\1\s\src\abcSetup\Release\abc_3.0.0.$(Rev:r).msi"

Error:

Rev:r : The term 'Rev:r' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again. At C:\Softwares\vsts-agent-win-x86-2.147.1_work_temp\fef4cc6a-e677-4a08-ab29-73c7c31da755.ps1:2 char:243 + ... ork\1\s\src\abcSetup\Release\abc_3.0.0.$(Rev:r).msi" + ~~~~~ + CategoryInfo : ObjectNotFound: (Rev:r:String) [], ParentContainsErrorRecordException + FullyQualifiedErrorId : CommandNotFoundException

[error]PowerShell exited with code '1'.

[section]Finishing: Renaming the .MSI File

Shayki Abramczyk
  • 36,824
  • 16
  • 89
  • 114
PDBR
  • 331
  • 1
  • 7
  • 17
  • i think it only works in build id, so you can use buildid variable for that – 4c74356b41 Mar 07 '19 at 13:22
  • @4c74356b41 you can not use this in buildid (as you can not configure this, this is an incrementing integer). You propably mean the buildnumber (variable 'build.buildnumber') – D.J. Mar 07 '19 at 13:39
  • maybe, i dont exactly remember, i dont use those 2 all that much – 4c74356b41 Mar 07 '19 at 13:45
  • 1
    Possible duplicate of [How to receive Revision in Azure Pipelines YAML build definition](https://stackoverflow.com/questions/54742908/how-to-receive-revision-in-azure-pipelines-yaml-build-definition) – Shayki Abramczyk Mar 07 '19 at 14:23
  • Possible duplicate of [Custom TFS Enviroment Variable doesn't read $(Date)](https://stackoverflow.com/questions/48094110/custom-tfs-enviroment-variable-doesnt-read-date) – Matt Mar 08 '19 at 15:18
  • @PatrickLu-MSFT, Myself fixed this issue. Thanks for your response and for your inputs. – PDBR Mar 13 '19 at 05:51
  • @PDBR Glad to hear this, always better when you fix it yourself; as you understand how it works!:). If you have time, you could also share the solution here and mark it as an answer,which will also helps others in the community. – PatrickLu-MSFT Mar 13 '19 at 06:18
  • 1
    @PatrickLu-MSFT, Thanks for your response.Sure I will share the answer here. Solution : abc_$(Build.BuildNumber).msi is used in the build definition and under the options I used 3.0.0.$(Rev:r). Then the resulting build version is abc_3.0.0.1.msi and abc_3.0.0.2.msi ...so on..This way I solved this issue. Thanks. – PDBR Mar 13 '19 at 11:16
  • I am not sure how to mark this as answer. Please help me to accept my answer as a solution to this or you can accept this as answer. – PDBR Mar 13 '19 at 11:17

3 Answers3

14

In Azure DevOps $(rev:.r) is a special variable format that only works in the Build Number field in the editor.

Use $(Rev:.rr) to ensure that every completed build has a unique name. When a build is completed, if nothing else in the build number has changed, the Rev integer value is incremented by one.

Source: Specify general build definition settings

BUILD_BUILDNUMBER is a predefined variable. If you create a definition variable with this name, any tasks that reference it will get this variable's value and not the system-defined value.

If you're looking to create a counter variable, you can do so with the counter() expression. See this documentation for details. It's yaml-centric but will work in the editor as well.

PatrickLu-MSFT
  • 49,478
  • 5
  • 35
  • 62
2

Value of $(Rev:r) can not be accessed within a task. It can only be accessed to define build number for ex:

name: $(Build.SourceBranchName)-$(releaseVersion)$(Rev:.r)
trigger:
 - main
pool:
 vmImage: ubuntu-latest

Here name is the variable used to define build number in Yaml pipelines. And releaseVersion is a custom variable defined in Pipelines->Library. Once we set this it can be accessed inside task as below:

- task: CmdLine@2
  inputs:
    script: >
      nuget pack ClassLibrary1/ClassLibrary1.csproj  
      -OutputDirectory $(Build.ArtifactStagingDirectory)
      -NonInteractive 
      -Properties Configuration=release
      -Version $(Build.BuildNumber)
      -Verbosity Detailed 
      -IncludeReferencedProjects
GPuri
  • 495
  • 4
  • 11
0

There is an environment variable RELEASE-RELEASENAME set on agent which returns the exact release name as displayed on Azure DevOps. This includes the value of $(Rev:r).

Rfd
  • 115
  • 1
  • 2
  • 10