How to convert YAML array to string?

Hi, I have a declarative pipeline script that processes parameters from a YAML file. One of the parameters is the agent on which to run a job:

---
agents:
  - myAgent

In the script I want to use the agent specified by agents as a string:

def parameters = readYaml file: 'example.yaml'
node(parameters.agents)
...

This does not work because agents is an array not a string. The intention is that agents would only ever contain one string. How can I obtain that first string?

Fixed by using YAML string value instead of array.

1 Like