Azure管道:递归文件模式在搜索现有文件时会产生0匹配

发布于 2025-02-01 18:23:10 字数 2460 浏览 4 评论 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

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文