从YAML管道中删除web.config中的特定行

huangapple go评论86阅读模式
英文:

Remove specific lines from web.config using YAML pipelines

问题

期望:删除带有注释的行

  1. <service behaviorConfiguration="mybehavior" name="">
  2. <endpoint address="" binding="netTcpBinding" bindingConfiguration="" contract=""/>
  3. </service>
  4. <service behaviorConfiguration="mybehavior" name="">
  5. <endpoint address="" binding="netTcpBinding" bindingConfiguration="" contract=""/>
  6. </service>

关于此,我在当前的YAML管道中有以下任务(CopyFile@2):

  1. - task: CopyFiles@2
  2. displayName: web.config复制到包中
  3. condition: eq(variables.generateConfigs, true)
  4. inputs:
  5. SourceFolder: '$(ReleasesPath.SourceFolderName)'
  6. Contents: |
  7. Web.config
  8. TargetFolder: '$(CopyPath.TragetFolderName)'
  9. CleanTargetFolder: false
  10. preserveTimestamp: true
英文:

I want to delete some specific lines from my web.config while copying the file to the artifact using azure yaml pipelines.

Actual:

  1. `<service behaviorConfiguration="mybehavior" name="">
  2. <endpoint address="" binding="netTcpBinding" bindingConfiguration="" contract=""/>
  3. <!--<endpoint address="mex" binding="mexTcpBinding" contract="IMetadataExchange"/>-->
  4. </service>
  5. <service behaviorConfiguration="mybehavior" name="">
  6. <endpoint address="" binding="netTcpBinding" bindingConfiguration="" contract=""/>
  7. <!--<endpoint address="mex" binding="mexTcpBinding" contract="IMetadataExchange"/>-->
  8. </service>`

Expected: delete lines with comments

  1. `<service behaviorConfiguration="mybehavior" name="">
  2. <endpoint address="" binding="netTcpBinding" bindingConfiguration="" contract=""/>
  3. </service>
  4. <service behaviorConfiguration="mybehavior" name="">
  5. <endpoint address="" binding="netTcpBinding" bindingConfiguration="" contract=""/>
  6. </service>`

For information, I have the following task (CopyFile@2) in my current yml pipelines:

  1. `- task: CopyFiles@2
  2. displayName: Copy web config into the Package
  3. condition: eq(variables.generateConfigs, true)
  4. inputs:
  5. SourceFolder: '$(ReleasesPath.SourceFolderName)'
  6. Contents: |
  7. Web.config
  8. TargetFolder: '$(CopyPath.TragetFolderName)'
  9. CleanTargetFolder: false
  10. preserveTimestamp: true`

答案1

得分: 0

我添加了一个PowerShell任务,用于从Web.Config文件中删除注释行,然后添加了一个复制任务来将Web.Config文件复制到目标位置。

Web.Config文件:-

从YAML管道中删除web.config中的特定行

以下是带有PowerShell和复制任务的我的YAML代码:-

  1. # 启动管道
  2. # 从一个最小的管道开始,您可以根据需要进行自定义以构建和部署您的代码。
  3. # 添加构建、运行测试、部署等步骤:
  4. # https://aka.ms/yaml
  5. 触发器:
  6. - 主要
  7. :
  8. vmImage: windows-latest
  9. 步骤:
  10. - 脚本: echo 你好,世界!
  11. displayName: '运行一行脚本'
  12. - 脚本: |
  13. echo 添加其他任务来构建、测试和部署您的项目。
  14. echo 请参阅 https://aka.ms/yaml
  15. displayName: '运行多行脚本'
  16. - 任务: PowerShell@2
  17. inputs:
  18. targetType: 'inline'
  19. script: |
  20. Get-Location
  21. Get-ChildItem .
  22. - 任务: PowerShell@2
  23. inputs:
  24. targetType: 'inline'
  25. script: |
  26. $configPath ='$(Build.SourcesDirectory)\Web.Config'
  27. $content = Get-Content $configPath
  28. $content = $content | Where-Object { $_ -notmatch '<!--' }
  29. $content | Set-Content $configPath
  30. - 任务: CopyFiles@2
  31. inputs:
  32. SourceFolder: '$(Build.SourcesDirectory)'
  33. Contents: 'Web.Config'
  34. TargetFolder: '$(Build.ArtifactStagingDirectory)'
  35. - 任务: PublishBuildArtifacts@1
  36. inputs:
  37. PathtoPublish: '$(Build.ArtifactStagingDirectory)'
  38. ArtifactName: 'drop'
  39. publishLocation: 'Container'

输出:-

从YAML管道中删除web.config中的特定行

从YAML管道中删除web.config中的特定行

从YAML管道中删除web.config中的特定行

打开了Web.Config文件,PowerShell任务已删除了注释行,如下所示:-

从YAML管道中删除web.config中的特定行

从YAML管道中删除web.config中的特定行

英文:

I added a Powershell task to remove the commented lines from the Web.Config file and then added the Copy task to Copy the Web.Config file to the destination.

Web.Config file :-

从YAML管道中删除web.config中的特定行

Below is my yaml code with Powershell and Copy task:-

  1. # Starter pipeline
  2. # Start with a minimal pipeline that you can customize to build and deploy your code.
  3. # Add steps that build, run tests, deploy, and more:
  4. # https://aka.ms/yaml
  5. trigger:
  6. - main
  7. pool:
  8. vmImage: windows-latest
  9. steps:
  10. - script: echo Hello, world!
  11. displayName: &#39;Run a one-line script&#39;
  12. - script: |
  13. echo Add other tasks to build, test, and deploy your project.
  14. echo See https://aka.ms/yaml
  15. displayName: &#39;Run a multi-line script&#39;
  16. - task: PowerShell@2
  17. inputs:
  18. targetType: &#39;inline&#39;
  19. script: |
  20. Get-Location
  21. Get-ChildItem .
  22. - task: PowerShell@2
  23. inputs:
  24. targetType: &#39;inline&#39;
  25. script: |
  26. $configPath =&#39;$(Build.SourcesDirectory)\Web.Config&#39;
  27. $content = Get-Content $configPath
  28. $content = $content | Where-Object { $_ -notmatch &#39;&lt;!--&#39; }
  29. $content | Set-Content $configPath
  30. - task: CopyFiles@2
  31. inputs:
  32. SourceFolder: &#39;$(Build.SourcesDirectory)&#39;
  33. Contents: &#39;Web.Config&#39;
  34. TargetFolder: &#39;$(Build.ArtifactStagingDirectory)&#39;
  35. - task: PublishBuildArtifacts@1
  36. inputs:
  37. PathtoPublish: &#39;$(Build.ArtifactStagingDirectory)&#39;
  38. ArtifactName: &#39;drop&#39;
  39. publishLocation: &#39;Container&#39;

Output:-

从YAML管道中删除web.config中的特定行

从YAML管道中删除web.config中的特定行

从YAML管道中删除web.config中的特定行

Opened the Web.Config file and the commented lines were removed by the PowerShell task like below:-

从YAML管道中删除web.config中的特定行

从YAML管道中删除web.config中的特定行

huangapple
  • 本文由 发表于 2023年2月7日 04:54:36
  • 转载请务必保留本文链接:https://go.coder-hub.com/75366490.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定