# How to convert YAML array to string?

**URL:** <https://community.jenkins.io/t/how-to-convert-yaml-array-to-string/9461>\
**Category:** Using Jenkins\
**Created:** [September 7, 2023, 1:42pm UTC](https://community.jenkins.io/t/how-to-convert-yaml-array-to-string/9461 "2023-09-07T13:42:52Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![DavidA2014](https://dub1.discourse-cdn.com/flex013/user_avatar/community.jenkins.io/davida2014/32/88_2.png) [@DavidA2014](https://community.jenkins.io/u/DavidA2014)\
**Post date:** [September 7, 2023, 1:42pm UTC](https://community.jenkins.io/t/how-to-convert-yaml-array-to-string/9461/1 "2023-09-07T13:42:52Z")

</div>

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:

```auto
---
agents:
  - myAgent

```

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

```auto
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?

---

<div class="post-metadata">

**Author:** ![DavidA2014](https://dub1.discourse-cdn.com/flex013/user_avatar/community.jenkins.io/davida2014/32/88_2.png) [@DavidA2014](https://community.jenkins.io/u/DavidA2014)\
**Post date:** [September 7, 2023, 4:18pm UTC](https://community.jenkins.io/t/how-to-convert-yaml-array-to-string/9461/2 "2023-09-07T16:18:04Z")

</div>

Fixed by using YAML string value instead of array.
