Answers: <p>I found a way to set environmental variables globally from a file!
  I'm using envInject for loading variables from a file.</p>
  
  <p>For example, lets say I have a file that is called "versionNumber.txt" and that it's created during the build process. Maybe I update it in every build, or any other way. then I create a prosFile that can be identified by the envInject, by running a batch script:</p>
  
  <pre><code>set /p VERSION_NUM=&lt;versionNumber.txt
  </code></pre>
  
  <p>Let's assume my version number was 1.5.5.10. so now my VERSION_NUM equals that string.
  now VERSION_NUM has the value that I want. But it's local, it won't help me. so I rewrite it to a file in the following format (also, using a batch script):</p>
  
  <pre><code>echo VERSION_NUM=%VERSION_NUM% &gt; C:\Temp\prosFile
  </code></pre>
  
  <p>now I have a file that contains the following content:</p>
  
  <pre><code>VERSION_NUM=1.5.5.10
  </code></pre>
  
  <p>And now I just need to load the file using the envInject plugin:</p>
  
  <p><a href="https://i.sstatic.net/drZCv.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/drZCv.png" alt="Loading environmental variables from &quot;prosFile&quot; file"></a></p>
  
  <p>And now I have an environmental variable named VERSION_NUM that can be used anywhere in Jenkins. But I wanted to make it the subject of my email, so I'll simply do (in windows, in linux it might be different):</p>
  
  <p><a href="https://i.sstatic.net/66cLI.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/66cLI.png" alt="Version Number as the email subject"></a></p>
  
  <p>That's it!</p>
  
Answers: CC BY-SA 3.0
Answers: 2017-12-11T14:25:38.590Z
Answers: I don't think that's true, and I couldn't find that in the documentation. This is what's written there:
  <br/>
  _The /P switch allows you to set a variable equal to a line of input entered by the user._ 
  _The Prompt string is displayed before the user input is read._
   (from [SET documentation](https://ss64.com/nt/set.html))
Answers: Noam Ohana
Answers: CC BY-SA 3.0
Answers: 2017-12-11T14:27:13.897Z
Answers: Additionally, if I don't use the envInject it won't at all be available for **any** part of the build. In Jenkins I mean.
Answers: Noam Ohana
Answers: CC BY-SA 3.0
Answers: 2017-12-11T14:30:51.503Z
Answers: My bad, messed it up with `setx`.
Answers: Tensibai
Answers: CC BY-SA 3.0
Answers: 2017-12-11T08:01:21.447Z
Answers: 2017-12-11T08:08:57.770Z
Answers: 2017-12-11T08:08:57.770Z
Answers: Noam Ohana
Answers: <p>You should be able to pass the current params as an argument to the batch file and then assign them to a variable used in the batch file.
  You can have this step as the post-build step before you call the email plugin.</p>
  
Answers: CC BY-SA 3.0
Answers: 2017-12-11T07:05:28.397Z
Answers: Can you give an example? I'm not sure how it can be done
Answers: Noam Ohana
Answers: CC BY-SA 3.0
Answers: 2017-12-12T06:03:05.787Z
Answers: Use this to pass the variables to the batch file:
Answers: arv_b
Answers: CC BY-SA 3.0
Answers: 2017-12-11T06:31:23.667Z
Answers: 2017-12-11T06:31:23.667Z
Answers: arv_b
Answers: <p>Sorry.. the previous post was incomplete as I hit enter. Though you have solved the issue, I'm pointing out how you can capture env variables into the batch file.</p>
  
  <p>Use the same method to read the contents of the file into a variable:</p>
  
  <p><code>set /p VERSION_NUM=&lt;versionNumber.txt</code></p>
  
  <p>and when calling the batch file:</p>
  
  <p><code>call catchmyvar.bat %VERSION_NUM%</code></p>
  
  <p>and in the batch file 'catchmyvar.bat`, set the parameter to another variable that's local to your batch file:</p>
  
  <p><code>SET VER_NUM=%1</code></p>
  
  <p>This should ensure you can capture the env variables set outside the batch file into the current context</p>
  
Answers: CC BY-SA 3.0
Answers: 2017-12-12T17:07:34.610Z
Answers: You can edit your previous post, no need to add a new one. Please combine the content of your posts into one of them and delete the other. Thx.
Answers: Dan Cornilescu
Answers: CC BY-SA 3.0
Answers: 2017-12-12T06:52:52.280Z
Answers: 2017-12-12T06:52:52.280Z
Answers: arv_b
Body: <p>I would like to send an email at the end of my build to inform success or failure. I'm using the email ext-plugin for Jenkins. I want the version number of the build to be the subject of the email.</p>
  
  <p>The problem is that the version is something that changes in each build, so I need to somehow edit an environmental variable to hold the version number each time (I have a script that saves it into a file). This is the default configuration: 
  <a href="https://i.sstatic.net/lIPCv.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/lIPCv.png" alt="enter image description here"></a></p>
  
  <p>I would like to have, for example, set the version number into a variable using windows batch script, like this:</p>
  
  <pre><code>rem # Loading version File number
  set MY_BUILD_VERSION=&lt;myVersionFile.txt
  rem # Loading content
  set MY_BUILD_CONTENT=&lt;myContentFile.txt
  </code></pre>
  
  <p>And using it in the email plugin, like this:
  <a href="https://i.sstatic.net/Jlj9Q.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/Jlj9Q.png" alt="enter image description here"></a></p>
  
  <p>The problem is that the environmental variables aren't recognized outside the .bat file they are being run from, although I'm using the envInject plugin, the documentation says that what's run from a script won't be recognized outside of it.</p>
  
  <p>Is there any way to load data into the email plugin from a file, or any other dynamic way to load my version number dynamically?</p>
  
Tags: <jenkins><windows><shell-script>
Title: Jenkins - sending email after build with the build version as a subject
UserDisplayName: Noam Ohana
ThreadText: # Jenkins - sending email after build with the build version as a subject
  
  (Asked by: username_0 on 2017-12-10)
  
  I would like to send an email at the end of my build to inform success or failure. I'm using the email ext-plugin for Jenkins. I want the version number of the build to be the subject of the email.
  
  The problem is that the version is something that changes in each build, so I need to somehow edit an environmental variable to hold the version number each time (I have a script that saves it into a file). This is the default configuration:
  [![enter image description here](https://i.sstatic.net/lIPCv.png)](https://i.sstatic.net/lIPCv.png)
  
  I would like to have, for example, set the version number into a variable using windows batch script, like this:
  
  ```
  rem # Loading version File number
  set MY_BUILD_VERSION=<myVersionFile.txt
  rem # Loading content
  set MY_BUILD_CONTENT=<myContentFile.txt
  
  ```
  
  And using it in the email plugin, like this:
  [![enter image description here](https://i.sstatic.net/Jlj9Q.png)](https://i.sstatic.net/Jlj9Q.png)
  
  The problem is that the environmental variables aren't recognized outside the .bat file they are being run from, although I'm using the envInject plugin, the documentation says that what's run from a script won't be recognized outside of it.
  
  Is there any way to load data into the email plugin from a file, or any other dynamic way to load my version number dynamically?
  
  **Tags:** jenkins, windows, shell-script
  
  
  ---
  
  ## 3 answers
  
  ### Answer by username_0 on 2017-12-11. Score: 1 | Accepted answer
  
  I found a way to set environmental variables globally from a file!
  I'm using envInject for loading variables from a file.
  
  For example, lets say I have a file that is called "versionNumber.txt" and that it's created during the build process. Maybe I update it in every build, or any other way. then I create a prosFile that can be identified by the envInject, by running a batch script:
  
  ```
  set /p VERSION_NUM=<versionNumber.txt
  
  ```
  
  Let's assume my version number was 1.5.5.10. so now my VERSION\_NUM equals that string.
  now VERSION\_NUM has the value that I want. But it's local, it won't help me. so I rewrite it to a file in the following format (also, using a batch script):
  
  ```
  echo VERSION_NUM=%VERSION_NUM% > C:\Temp\prosFile
  
  ```
  
  now I have a file that contains the following content:
  
  ```
  VERSION_NUM=1.5.5.10
  
  ```
  
  And now I just need to load the file using the envInject plugin:
  
  [![Loading environmental variables from "prosFile" file](https://i.sstatic.net/drZCv.png)](https://i.sstatic.net/drZCv.png)
  
  And now I have an environmental variable named VERSION\_NUM that can be used anywhere in Jenkins. But I wanted to make it the subject of my email, so I'll simply do (in windows, in linux it might be different):
  
  [![Version Number as the email subject](https://i.sstatic.net/66cLI.png)](https://i.sstatic.net/66cLI.png)
  
  That's it!
  
  > **Comments:**
  > **username_0**: I don't think that's true, and I couldn't find that in the documentation. This is what's written there: <br/> _The /P switch allows you to set a variable equal to a line of input entered by the user._  _The Prompt string is displayed before the user input is read._  (from [SET documentation](https://ss64.com/nt/set.html))  
  > **username_0**: Additionally, if I don't use the envInject it won't at all be available for **any** part of the build. In Jenkins I mean.  
  > **username_1**: My bad, messed it up with `setx`.  
  
  ---
  
  ### Answer by username_2 on 2017-12-11. Score: 0
  
  You should be able to pass the current params as an argument to the batch file and then assign them to a variable used in the batch file.
  You can have this step as the post-build step before you call the email plugin.
  
  > **Comments:**
  > **username_0**: Can you give an example? I'm not sure how it can be done  
  > **username_2**: Use this to pass the variables to the batch file:  
  
  ---
  
  ### Answer by username_2 on 2017-12-12. Score: 0
  
  Sorry.. the previous post was incomplete as I hit enter. Though you have solved the issue, I'm pointing out how you can capture env variables into the batch file.
  
  Use the same method to read the contents of the file into a variable:
  
  `set /p VERSION_NUM=<versionNumber.txt`
  
  and when calling the batch file:
  
  `call catchmyvar.bat %VERSION_NUM%`
  
  and in the batch file 'catchmyvar.bat`, set the parameter to another variable that's local to your batch file:
  
  `SET VER_NUM=%1`
  
  This should ensure you can capture the env variables set outside the batch file into the current context
  
  > **Comments:**
  > **username_3**: You can edit your previous post, no need to add a new one. Please combine the content of your posts into one of them and delete the other. Thx.  
  
  ---
  
  