Azure管道:递归文件模式在搜索现有文件时会产生0匹配
我们的管道包括以下任务:
- task: RegexReplace@3
displayName: "Replace token on $(resourceName)"
condition: eq(variables['Agent.MachineName'], variables['TargetMachine'])
inputs:
inputSearchPattern: '**\*tokenized.config'
findRegex: '\${ReplaceMe}'
replaceRegex: 'Tokenization replacement successful'
useUTF8: false
useRAW: true
条件效果很好。但是,当我们到达尝试查找匹配文件的部分时,构建日志总是报告以下内容:
开始:在myTargetServer上更换令牌
================================================ ========================
任务:Regex Find&更换
描述:查找&使用正则表达式
替换版本:3.3.11
作者:knom
帮助:更多信息
================================================ ========================
搜索模式为** \*tokenized.config
找到0个文件
用代币化替换$ {replaceme}成功(ASCII,RAW)
完成:更换mytargetServer上的令牌
,匹配了0个文件,因此不会发生替换。无论我们如何调整递归文件模式,都会发生这种情况。
我们已经尝试了:
**/*。tokenized.config
** \*。tokenized.config
**/*tokenized.config
** \*tokenized.config
$(pipeline.workspace)\ drop \*。tokenized.config
我的理解是,上面的第一个模式应该有效并找到我们的project .tokenized.config
文件。文件结构如下:
- 解决方案文件夹
- 项目文件夹
project.tokenized.config
- 项目文件夹
我们在指定文件模式时做错了什么?为什么递归搜索似乎不起作用,产生0匹配?
请注意,我们使用Regexreplace
任务,因为我们想在生产环境中以每服务器为单位修改特定的设置。据我们所知,替换
任务不支持这一点。
附录
以下任务在同一文件中更进一步,并且使用相同的文件模式,它们完全按照我们的期望执行。
- task: replacetokens@3
displayName: "Replace tokens in tokenized configuration files"
inputs:
rootDirectory: "$(sitePath)"
targetFiles: |
**/*.tokenized.config => *.config
**/*.tokenized.js => *.js
**/*.tokenized.json => *.json
encoding: "auto"
writeBOM: true
actionOnMissing: "warn"
keepToken: true
tokenPrefix: "${"
tokenSuffix: "}"
useLegacyPattern: false
enableTelemetry: false
- task: DeleteFiles@1
displayName: "Remove tokenized files"
inputs:
SourceFolder: $(sitePath)
contents: |
**/*.tokenized.config
**/*.tokenized.js
**/*.tokenized.json
Our pipeline includes the following task:
- task: RegexReplace@3
displayName: "Replace token on $(resourceName)"
condition: eq(variables['Agent.MachineName'], variables['TargetMachine'])
inputs:
inputSearchPattern: '**\*tokenized.config'
findRegex: '\${ReplaceMe}'
replaceRegex: 'Tokenization replacement successful'
useUTF8: false
useRAW: true
The condition works just fine. But when we get to the part where it's trying find matching files, the build log always reports the following:
Starting: Replace token on MYTARGETSERVER
=========================================================================
Task : RegEx Find & Replace
Description : Find & Replace using Regular Expressions
Version : 3.3.11
Author : knom
Help : More Information
=========================================================================
Search Pattern is **\*tokenized.config
Found 0 files
Replacing ${ReplaceMe} with Tokenization replacement successful (ASCII, RAW)
Finishing: Replace token on MYTARGETSERVER
As shown, 0 files were matched, so our replacements don't occur. This happens no matter how we adjust the recursive file pattern.
We have tried:
**/*.tokenized.config
**\*.tokenized.config
**/*tokenized.config
**\*tokenized.config
$(Pipeline.Workspace)\drop\*.tokenized.config
My understanding is that the first pattern above should work and find our project.tokenized.config
file. The file structure is as follows:
- Solution Folder
- Project Folder
Project.tokenized.config
- Project Folder
What are we doing wrong in specifying the file pattern? Why doesn't recursive search seem to work here, producing 0 matches?
Note that we use the RegexReplace
task because we want to modify specific settings on a per-server basis within our production environment. To our knowledge, the ReplaceTokens
task doesn't support that.
ADDENDUM
The following tasks are further down in the same file, and they execute exactly as we expect them to, using the same file patterns.
- task: replacetokens@3
displayName: "Replace tokens in tokenized configuration files"
inputs:
rootDirectory: "$(sitePath)"
targetFiles: |
**/*.tokenized.config => *.config
**/*.tokenized.js => *.js
**/*.tokenized.json => *.json
encoding: "auto"
writeBOM: true
actionOnMissing: "warn"
keepToken: true
tokenPrefix: "${"
tokenSuffix: "}"
useLegacyPattern: false
enableTelemetry: false
- task: DeleteFiles@1
displayName: "Remove tokenized files"
inputs:
SourceFolder: $(sitePath)
contents: |
**/*.tokenized.config
**/*.tokenized.js
**/*.tokenized.json
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论