首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在Azure Devops管道codeway.yml中使用通配符名称复制文件

问如何在Azure Devops管道codeway.yml中使用通配符名称复制文件
EN

Stack Overflow用户
提问于 2021-11-24 11:55:40
回答 1查看 92关注 0票数 0

我有一个带有.exe examle (hello/my-file-print-on-text-2.0.1-win-x64.exe)的文件,该文件的版本为2.0.1,之后的版本将更改为2.0.2。等等。

每当使用cp命令自动更新版本时,我想将这个相同的文件复制到不同的文件夹中。

我可以帮助如何使此文件名与通配符

我尝试了下面的方法,但它不起作用,这是在windows机器上,而不是linux。

代码语言:javascript
复制
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)"

如何使用带有通配符的cp命令当文件的版本发生变化时,应使用新名称进行复制?

EN

回答 1

Stack Overflow用户

发布于 2021-11-24 13:27:20

好的,您说您是在Windows中执行此操作,因此我将提供一个使用Powershell来实现您所需的解决方案(将单个可执行文件复制到一个名为的文件夹中,该文件夹的版本号来自)。这可以与Azure Pipeline中的powershell或pwsh任务类型一起使用:

代码语言:javascript
复制
# 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
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/70095669

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档