引用在 Rundeck 数据工作流步骤中创建的 json 列表值

Referencing json list value created in Rundeck Data Workflow step

Rundeck 作业:当我在数据工作流步骤中创建数据时 json list

{
"repo": ["repo1","repo2","repo3"],
"myrepo": "repo4"
}

下一步如何从内联脚本访问列表中的元素?

@stub.repo[1]@

不起作用

@stub.myrepo@

工作正常

Data Workflow step executed

脚本:

echo "value: @stub.repo[1]]@"
echo "value2: @stub.myrepo@"

结果:

value: 
value2: repo4

捕获该数组的最简单方法是使用 jq-JSON mapper log filter plugin in any step like the command step or script step (here are the releases, here is how to install the plugin, and here 日志过滤器的工作原理)。

使用此插件可以直接使用数组位置,例如:${data.data.0}${data.data.1}

您的 JSON 输出 testing 的作业定义示例。

- defaultTab: summary
  description: ''
  executionEnabled: true
  group: JSON
  id: f0d2843f-8de3-4984-a9ae-2fd7ab3963ae
  loglevel: INFO
  name: test-json-array
  nodeFilterEditable: false
  plugins:
    ExecutionLifecycle: null
  scheduleEnabled: true
  sequence:
    commands:
    - plugins:
        LogFilter:
        - config:
            filter: .[]
            logData: 'true'
            prefix: data
          type: json-mapper
      script: |-
        cat <<-END
        {
        "repo": ["repo1","repo2","repo3"],
        "myrepo": "repo4"
        }
        END
    - exec: echo ${data.data.0}
    keepgoing: false
    strategy: node-first
  uuid: f0d2843f-8de3-4984-a9ae-2fd7ab3963ae

Result.

有关插件的更多信息 here