Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VSTS Build: Replacing token with build number

I'm trying to update a web.config app setting called 'AppVersion' with the build number when building my application in VSTS.

Here are my build steps:

build steps

The 'Replace tokens' step converts any variables you set for your build and replaces the tokens you've set in your config files. This part works but what it won't do is get an environment variable like the build number and do a replace. It will just replace whatever text has been specified. Here's my build variables:

build variables

So after the build step is completed, my app setting is...

<add key="AppVersion" value="$(BuildNumber)" />

when it should be something like...

<add key="AppVersion" value="20160520.1" />

Can anyone point me in the right direction? Many thanks.

like image 270
Johnny Rambo Avatar asked May 20 '16 12:05

Johnny Rambo


2 Answers

I did something similar using the "Replace Tokens in **/*config" task.

To update the value for the key "AppVersion" with the current build number, your line should look like the following,

<add key="AppVersion" value="#{Build.BuildNumber}#" />
like image 185
Robblis Avatar answered Dec 29 '22 03:12

Robblis


You can add a PowerShell script task before "Replace Token" task to pass the "BuildNumber" to "AppVersion" variable as following. enter image description here

like image 23
Eddie Chen - MSFT Avatar answered Dec 29 '22 03:12

Eddie Chen - MSFT