skip to Main Content

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 .

2

Answers


  1. Based on your post’s tags, I’ll assume you’re 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
    
    Login or Signup to reply.
  2. 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
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search