Passing information from one job to another


I have a freestyle project that runs a batch file which does the build job. During execution of that batch file, some information are evaluated and assigned to the environment variables VERSION and VERSION_ID.
After the batch file is terminated I trigger a second parametrized freestyle project and I pass the values of these environment variable as parameters.

Here is what I did:

  1. I create the required environment variables using Environment Injector plugin.
    2.Then I run my batch file. (Note that the expected values of the variables are printed to the console output!)
  2. I run the second job with the variables passed as parameters

But the values passed to the second job are the initial values from the first screenshot and not the updated value after the batch file execution.
Same happens when i echo out the values in a second batch file step.

What am I doing wrong?

I also tried it with a pipeline, where information evaluated by TEST_JOB_A should be passed to TEST_JOB_B. But I have no idea how to achieve this.

pipeline {
	agent none
	stages {
		stage('Build') {
			steps {
				build job: 'TEST_JOB_A', parameters: [string(name: 'PARAMETER_A', value: "testA")]
		stage('Create Installer') {
			steps {
				build job: 'TEST_JOB_B', parameters: [string(name: 'VERSION', value: env.VERSION), string(name: 'VERSION_ID', value: env.VERSION_ID), string(name: 'BUILD_NR', value: env.BUILD_NUMBER)]

Has someone an idea?
Thanks in advance!


Environment variables are process specific and passed to child processes usually but parent process never see changes to them done by child processes. So when you call your bat step a new cmd process is started with your environment variables initial value. The variables are now modified and inside the cmd process the changes are visible. But as soon as the cmd process ends the changes are lost.
You will need to write the changed values to a file (as a java properties file) that you read in jenkins and then pass it on. In free style jobs you can pass parameters from properties file.

Writing the values to a file solved the problem! Thanks!