Home > Software design >  How to copy the file using Wildcard name in Azure Devops pipeline codeway.yml
How to copy the file using Wildcard name in Azure Devops pipeline codeway.yml

Time:11-25

i have a file with .exe examle (hello/my-file-print-on-text-2.0.1-win-x64.exe) and this file having version as 2.0.1 and later builds this version will be changed to 2.0.2.. so on.

this same file i want to copy into different folder with versions whenever the version get updated automatically using cp command.

could some help how to make this file name with wildcard

i tried below ways but it didnt work and this is in windows machine not linux.

cp "hello/my-file-print-on-text-*-win-x64.exe)" "hello/my-file-print-on-text.exe)"


cp "hello/my-file-print-on-text*-win-x64.exe)" "hello/my-file-print-on-text.exe)"

how to use cp command with wildcard the version of file whenever it gets changed copy should happen with new name?

CodePudding user response:

OK, so you said that you were doing this in Windows, so I'll give you one solution that uses Powershell to accomplish what you're looking for (copy a single exe to a folder named with a version number that comes from). This can be used with the powershell or pwsh task types in Azure Pipelines:

# Find the EXE to copy, get the first result
$exeFile = (Get-ChildItem hello/my-file-print-on-text-*-win-x64.exe | 
    Select-Object -First 1 Name).Name

# if the name of the file has some form of version in the name,
if ($exeFile -match "my-file-print-on-text-(.*)-win-x64.exe") {
    # grab the version
    $version = $Matches[1]

    # change this to the structure of the folder name you want
    $targetFolder = "path-containing-$version-number"
 
    # verify or create the target folder
    if (!(Test-Path $targetFolder)) { 
        New-Item -ItemType Directory $targetFolder 
    }

    # and then copy the EXE there
    Copy-Item $n $targetFolder
}
  • Related