Reputation: 21
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
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
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:
#{Build.BuildNumber}#
pattern in the driverVer.inf in the repo:[Version]
DriverVer=1.0.14.#{Build.BuildNumber}#
$(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'
[Version]
DriverVer=1.0.14.7
Upvotes: 0