jenkins 添加数组项或合并两个yaml文件

isr3a4wc  于 2023-08-03  发布在  Jenkins
关注(0)|答案(1)|浏览(148)

这是file-a.yaml

unclassified:
  sonarGlobalConfiguration:
    buildWrapperEnabled: false
    installations:
      - credentialsId: "ID1"
        name: "sonarqube"
        serverUrl: "https://example.com"
        triggers:
          skipScmCause: false
          skipUpstreamCause: false
      - credentialsId: "ID2"
        name: "sonarqube-2"
        serverUrl: "https://example.co.uk"
        triggers:
          skipScmCause: false
          skipUpstreamCause: false

字符串
这是file-b.yaml

unclassified:
  sonarGlobalConfiguration:
    installations:
      - credentialsId: "ID-3"
        name: "sonarqube-3"
        serverUrl: "https://example.org"
        triggers:
          skipScmCause: false
          skipUpstreamCause: false


我想合并这两个文件,这样file-a.yaml在unclassificed.sonarGlobalConfiguration.installations下包含3个项目
合并这两个文件或仅向安装阵列中添加一个新项目。这可以用YQ实现吗?
我尝试了几种YQ命令的组合,但是失败得很惨-以前有人做过这种事情吗?

4ioopgfo

4ioopgfo1#

使用最新的yqv4.34.2):

$ yq ea '. as $item ireduce ({}; . *+ $item )' file-a.yaml file-b.yaml
unclassified:
  sonarGlobalConfiguration:
    buildWrapperEnabled: false
    installations:
      - credentialsId: "ID1"
        name: "sonarqube"
        serverUrl: "https://example.com"
        triggers:
          skipScmCause: false
          skipUpstreamCause: false
      - credentialsId: "ID2"
        name: "sonarqube-2"
        serverUrl: "https://example.co.uk"
        triggers:
          skipScmCause: false
          skipUpstreamCause: false
      - credentialsId: "ID-3"
        name: "sonarqube-3"
        serverUrl: "https://example.org"
        triggers:
          skipScmCause: false
          skipUpstreamCause: false

字符串

相关问题