<p>You can use Jenkins DSL and pass the environment variable as mentioned in below links:</p>

<p><a href="https://jenkins.io/doc/book/pipeline/syntax/#environment" rel="nofollow noreferrer">https://jenkins.io/doc/book/pipeline/syntax/#environment</a>
<a href="https://jenkins.io/doc/pipeline/steps/workflow-basic-steps/#withenv-set-environment-variables" rel="nofollow noreferrer">https://jenkins.io/doc/pipeline/steps/workflow-basic-steps/#withenv-set-environment-variables</a></p>

CC BY-SA 4.0
2019-11-13T20:01:49.780Z
You don't get a question. I need variables passed in a time of generating the job via Job DSL, so when I start that job it will be already there.
mate200
CC BY-SA 4.0
2019-08-17T03:55:21.777Z
2019-08-17T03:55:21.777Z
Khushboo Kumari
<p>This might help you with your problem.
In the normal pipeline or any Jenkins job, we can define parameters which can be accessed via say <code>${env.SOME_VARIABLE}</code></p>

<p>My solution for using environment variables in the Jenkins Multibranch Pipeline.
Scenario. Say you have a variable named VARIABLE whose value is <code>123456789</code>.</p>

<p><strong>Create a secret text with id and description.</strong></p>

<ul>
<li>Secret Text: 123456789</li>
</ul>

<p><strong>NOTE</strong>: In Jenkins, the secret text will be completely hidden.</p>

<ul>
<li>Id: VARIABLE</li>
</ul>

<p><strong>NOTE</strong>: You can define it as you want. If left empty a random value will be assigned to it in the form as45f2sf-43rs-4sdf-s3f3-329f9bc9ae269</p>

<ul>
<li>Description: VARIABLE</li>
</ul>

<p><strong>NOTE</strong>: Description for the variable.</p>

<p>Once this is created in your multibranch pipeline Jenkinsfile, you can add the following to access those variables whenever required.</p>

<pre><code>pipeline {
  agent any
    environment { 
      SECRET_VARIABLE = credentials("VARIABLE") 
    }
    stages {
      stage('stage') {
        steps {
          echo "This is a secret variable: $SECRET_VARIABLE"
        }
      }
   }
}         
</code></pre>

<p>**PS: The variables will appear in a format <code>****</code> **</p>

CC BY-SA 4.0
2019-11-13T20:01:58.763Z
You don't get a question. I need variables passed in a time of generating the job via Job DSL, so when I start that job it will be already there.
mate200
CC BY-SA 4.0
2019-09-17T06:59:34.167Z
2019-09-17T07:08:10.917Z
2019-09-17T07:08:10.917Z
Manish_
<p>I want to pass some environment variables in the time of generating the multibranch pipelines, so upon the build start, it will already have these variables.</p>

<p>The only thing I found was this envInject plugin which is not supported by multibranch DSL generation.</p>

<p><a href="https://jenkinsci.github.io/job-dsl-plugin/#plugin/envinject" rel="noreferrer">https://jenkinsci.github.io/job-dsl-plugin/#plugin/envinject</a></p>

<p>Does anyone know the way to do that?</p>

CC BY-SA 4.0
2022-04-22T00:37:07.523Z
Did you ever figure this out?
Pytry
<jenkins><job-dsl>
Is it possible to pass environment variables to multibranch pipeline job in a time of generating it via DSL?
mate200
# Is it possible to pass environment variables to multibranch pipeline job in a time of generating it via DSL?

(Asked by: username_0 on 2019-08-16)

I want to pass some environment variables in the time of generating the multibranch pipelines, so upon the build start, it will already have these variables.

The only thing I found was this envInject plugin which is not supported by multibranch DSL generation.

<https://jenkinsci.github.io/job-dsl-plugin/#plugin/envinject>

Does anyone know the way to do that?

**Tags:** jenkins, job-dsl

> **Comments:**
> **username_1**: Did you ever figure this out?  

---

## 2 answers

### Answer by username_2 on 2019-08-17. Score: 1

You can use Jenkins DSL and pass the environment variable as mentioned in below links:

<https://jenkins.io/doc/book/pipeline/syntax/#environment>
<https://jenkins.io/doc/pipeline/steps/workflow-basic-steps/#withenv-set-environment-variables>

> **Comments:**
> **username_0**: You don't get a question. I need variables passed in a time of generating the job via Job DSL, so when I start that job it will be already there.  

---

### Answer by username_3 on 2019-09-17. Score: 1

This might help you with your problem.
In the normal pipeline or any Jenkins job, we can define parameters which can be accessed via say ${env.SOME_VARIABLE}
My solution for using environment variables in the Jenkins Multibranch Pipeline.
Scenario. Say you have a variable named VARIABLE whose value is 123456789.
Create a secret text with id and description.

Secret Text: 123456789

NOTE: In Jenkins, the secret text will be completely hidden.

Id: VARIABLE

NOTE: You can define it as you want. If left empty a random value will be assigned to it in the form as45f2sf-43rs-4sdf-s3f3-329f9bc9ae269

Description: VARIABLE

NOTE: Description for the variable.
Once this is created in your multibranch pipeline Jenkinsfile, you can add the following to access those variables whenever required.
pipeline {
  agent any
    environment { 
      SECRET_VARIABLE = credentials("VARIABLE") 
    }
    stages {
      stage('stage') {
        steps {
          echo "This is a secret variable: $SECRET_VARIABLE"
        }
      }
   }
}         

**PS: The variables will appear in a format **** **

> **Comments:**
> **username_0**: You don't get a question. I need variables passed in a time of generating the job via Job DSL, so when I start that job it will be already there.  

---

