Injecting environment variables into build

15 views
Skip to first unread message

Sholom Sanders

unread,
Mar 11, 2020, 2:11:03 PM3/11/20
to Jenkins Users
My Jenkins is installed on my Windows build machine. I have a directory on this machine which is dedicated to a Jenkins project.
Within this directory I have a  .bat file which sets up environment variables, e.g.

set GIT_UPDATE_DIR=$WORKSPACE
set MDM_SRC_DIR=$GIT_UPDATE_DIR
set GIT_BRANCH_FULL=MDM_R$branch
set WRKSPACE=$JENKINS_HOME\\workspace
set REL_NUMBER=$branch

The source code is in GIT. I want to inject these variables into the build after the SCM. In the Build Environment of the Project Configure section, I selected "Inject environment variables to the build process" and gave the full path of the file on the build machine. In the Build section, the first thing I do is execute a Windows Batch command  which only has "set". When I do the build, the log shows the script being run with all the variables. However, the "set" command does not show any of the variables being available. What am I doing wrong?

Gianluca

unread,
Mar 13, 2020, 6:22:33 PM3/13/20
to Jenkins Users
In my Jenkins setup I don't have "Inject environment variables" in the project configuration, so I'm assuming you are using a specific plugin to achieve that.
It would be great to know which one.

From what I can guess you may using this one: https://plugins.jenkins.io/envinject/
If so, then the documentation says that the file you specify as to provide the environment variables in the standard "Java property file format" and if you are passing the .bat file, then you are passing a file with the wrong format.
Reply all
Reply to author
Forward
0 new messages