title: Use Object Returned by readYaml from file in Declarative Jenkinsfile
body: <p>I want to read the contents of a yaml file in a declarative Jenkinsfile via the readYaml utility. My understanding is that readYaml should return a Map, however, the object type I am seeing returned is a String. This defeats the purpose of putting the data in a yaml file in the first place.</p>
  
  <p>Specifically, I want to get some values from a helm values.yaml file to set env values in the global environment section of the Jenkinsfile for all subsequent stages to be able to use. </p>
  
  <p>The <code>println valuesYaml.getClass()</code> returns java.lang.String which I think is not correct because this object comes from a nested yaml file so I think the returned object should be a map.</p>
  
  <p><a href="https://jenkins.io/doc/pipeline/steps/pipeline-utility-steps/#readyaml-read-yaml-from-files-in-the-workspace-or-text" rel="nofollow noreferrer">https://jenkins.io/doc/pipeline/steps/pipeline-utility-steps/#readyaml-read-yaml-from-files-in-the-workspace-or-text</a></p>
  
  <p>When the following echo statement runs <code>echo valuesYaml.appName.toString()</code> it errors out with the following error:</p>
  
  <p>org.jenkinsci.plugins.scriptsecurity.sandbox.RejectedAccessException: No such field found: field java.lang.String appName</p>
  
  <p>This is a snippet of the values.yaml I'm trying to read:</p>
  
  <pre><code>replicaCount: 1
  appName: test
  </code></pre>
  
  <pre><code>def loadValuesYaml(){
    def valuesYaml = readYaml (file: './chart/values.yaml')
    return valuesYaml;
  }
  
  pipeline {
    agent {
      label "jenkins-maven"
    }
  
    environment {
      valuesYaml = loadValuesYaml()
    }
    stages {
      stage('CICD Initialize') {
        steps {
          script{
            echo valuesYaml
            println valuesYaml.getClass()
          }
          echo valuesYaml.appName.toString()
        }
      }
  }
  </code></pre>