# How to use global variable in pipeline DSL?

**URL:** <https://community.jenkins.io/t/how-to-use-global-variable-in-pipeline-dsl/9258>\
**Category:** Ask a question\
**Created:** [August 29, 2023, 6:04am UTC](https://community.jenkins.io/t/how-to-use-global-variable-in-pipeline-dsl/9258 "2023-08-29T06:04:47Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![AramaMihai](https://avatars.discourse-cdn.com/v4/letter/a/858c86/32.png) [@AramaMihai](https://community.jenkins.io/u/AramaMihai)\
**Post date:** [August 29, 2023, 6:04am UTC](https://community.jenkins.io/t/how-to-use-global-variable-in-pipeline-dsl/9258/1 "2023-08-29T06:04:47Z")

</div>

Hello,

We have defined some Environment variables, under “Global Properties” (screenshot added).

 ![GlobalVariables](https://europe1.discourse-cdn.com/flex013/uploads/jenkins/original/2X/f/f58f718bf65e72d85547f5c257d57e82ccfdee63.png)

We now want to use the “pipeline\_repo\_ssh\_url\_d” variable in a job, defined as code, stored in a file in our repo.

The job definition is:

```auto
def envVar = getBinding().getVariables()['pipeline_repo_ssh_url_d']

pipelineJob("globalVariable-test") {
    description """
test job
    """
    parameters {
        stringParam("meta", "", "${envVar}")
    }
    properties {
        disableConcurrentBuilds()
    }
    environmentVariables {
        keepSystemVariables(true)
    }
    logRotator {
        daysToKeep(30)
        numToKeep(100)
    }
    quietPeriod(0)
    definition {
        cpsScm {
            lightweight(false)
            scm {
                git {
                    remote {
                        url("${envVar}")
                        credentials('github.geo.de-ssh')
                        refspec('$releaseBranch refs/heads/*:refs/remotes/origin/*')
                    }
                    extensions {
                        cloneOptions {
                            honorRefspec(true)
                        }
                        gitLFSPull()
                        pruneStaleBranch()
                    }
                    branches('$releaseBranch')
                }
            }
            scriptPath('JenkinsfileRelease')
        }
    }
}

```

I found [Jenkins Job DSL Plugin](https://jenkinsci.github.io/job-dsl-plugin/#path/javaposse.jobdsl.dsl.jobs.FreeStyleJob.environmentVariables-keepSystemVariables) , so that’s why I have this part added:

```
environmentVariables {
    keepSystemVariables(true)
}

```

but it does not explain how to actually use a global variable. I also tried with:

` remote { url("${pipeline_repo_ssh_url_d}") credentials('github.geo.de-ssh') refspec('$releaseBranch refs/heads/*:refs/remotes/origin/*') }`

and both of these return nothing. When the job configuration is opened, I see just an empty field (screenshot added).

 ![GlobalVariables2](https://europe1.discourse-cdn.com/flex013/uploads/jenkins/original/2X/0/07184a3557632be83ab0a8b7b84f28b631c011b2.png)

How do I actually call that variable?

Thank you!

---

<div class="post-metadata">

**Author:** ![AramaMihai](https://avatars.discourse-cdn.com/v4/letter/a/858c86/32.png) [@AramaMihai](https://community.jenkins.io/u/AramaMihai)\
**Post date:** [August 31, 2023, 11:13am UTC](https://community.jenkins.io/t/how-to-use-global-variable-in-pipeline-dsl/9258/2 "2023-08-31T11:13:06Z")

</div>

url(‘’‘$\u007Bpipeline\_repo\_ssh\_url\_d\u007D’‘’) - unicode representation of curly brackets; the job configuration sees this string; then when the build runs, it is able to interpret it and retrieve the variable value;
