shravya
shravya

Reputation: 21

How to use build number as part of INF driverVer

I am a beginner working on INF files. My .vcxproj file is having a property that uses 1.0.14.0 to use it in driverVer . My INF driverVer as follows DriverVer=04/10/2024,10.0.14.0

I would like to use build number in my INF file ,something like 1.0.14.$(build number).

How can I use azure build number to stamp my INF file ?

I tried using environment variable . But , the driverVer doesn’t pick the build number .

Upvotes: 1

Views: 126

Answers (2)

Architect Jamie
Architect Jamie

Reputation: 2569

Based on your post's tags, I'll assume your build agent is Windows based.

You can achieve the desired result by using a PowerShell Script Task just after your Get Sources step in your pipeline.

You could use this script:

# Get the build number from environment variable or build system
$buildNumber = $env:BUILD_BUILDNUMBER

# Path to driverVer.inf file (update this path if required
$infFilePath = "./driverVer.inf"

# Read the content of the file
$content = Get-Content -Path $infFilePath

# Define the regex pattern to capture only the final digit of the version number. Using capture groups
$pattern = '(DriverVer=\d+/\d+/\d+,\d+\.\d+\.\d+\.)(\d+)'

# Replace the final digit with the buildNumber using the regex pattern
$newContent = $content -replace $pattern, $1 + $buildNumber

# Write the updated content back to the file
Set-Content -Path $infFilePath -Value $newContent

Upvotes: 1

Miao Tian-MSFT
Miao Tian-MSFT

Reputation: 5522

You can use the replace token task to replace the DriverVer with the build number in your azure DevOps pipeline.

My test Steps:

  1. Install the extension to the organization.
  2. Use the #{Build.BuildNumber}# pattern in the driverVer.inf in the repo:
[Version]
DriverVer=1.0.14.#{Build.BuildNumber}#
  1. Use the following yaml to customize the build numbers. This is to make the variable $(Build.BuildNumber) only contains a single version number instead of the default Date + version number. Then use the replace token task to replace the #{Build.BuildNumber}# to the actual build number in the inf file.
trigger:
- none

pool:
  vmImage: windows-latest

name: $(Rev:r)

steps:
- script: echo '$(Build.BuildNumber)' # outputs customized build number

- task: replacetokens@6
  inputs:
    sources: '*.inf'
  1. When the build number is 7, the replaced driverVer.inf looks like the following one.
[Version]
DriverVer=1.0.14.7

Upvotes: 0

Related Questions