# Declarative pipeline syntax - variable scope?

**URL:** <https://community.jenkins.io/t/declarative-pipeline-syntax-variable-scope/9594>\
**Category:** Using Jenkins\
**Created:** [September 14, 2023, 3:41pm UTC](https://community.jenkins.io/t/declarative-pipeline-syntax-variable-scope/9594 "2023-09-14T15:41:01Z")\
**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 14, 2023, 3:41pm UTC](https://community.jenkins.io/t/declarative-pipeline-syntax-variable-scope/9594/1 "2023-09-14T15:41:01Z")

</div>

Hi, I have two stages, on different agents, that both need to access parameters from a yaml file. I am reading the file twice. How can I change the scope of yaml\_params so that I only need to read the file once?

```auto
pipeline {

    agent { label "agent_1" }

    parameters { string defaultValue: '', description: '', name: 'yaml_path', trim: true }

    stages {
        stage('run') {
            steps {
                script {                    
                    def yaml_params = readYaml file: params.yaml_path // Read the YAML file

                    <snip>                   
                }   
            }
        }  

        stage('zip') {
            agent { label "agent_2" }
            steps {
                script {                    
                    def yaml_params = readYaml file: params.yaml_path // Read the YAML file

                    <snip>                   
                }   
            }
        }                              
    }
}

```

---

<div class="post-metadata">

**Author:** ![emdepl](https://avatars.discourse-cdn.com/v4/letter/e/e480ec/32.png) [@emdepl](https://community.jenkins.io/u/emdepl)\
**Post date:** [September 14, 2023, 5:32pm UTC](https://community.jenkins.io/t/declarative-pipeline-syntax-variable-scope/9594/2 "2023-09-14T17:32:44Z")

</div>

```auto
def let_it 

pipeline {
  agent none

  stages {

    stage('Checkout') {
      steps {
        script {
          let_it = 'snow'
        }
      }
    } // .stage.checkout

    stage('Build') {
      steps {
        println "Weather is: " + let_it
        script {
          println " ... and in script: " + let_it
        }
      }
    } // .stage.build

  } // .stages
} // .pipeline

```
