问题
In Jenkins, is it possible to export windows batch variables as build parameters? I know using build parameters inside windows batch blocks is, I use it a lot.
For example, I have a windows batch block that creates a variable, say A, like
SET A="MyVar"
Is it possible to use it in running MSBuild, passing it like it was a build parameter, in the (working) syntax of /p:AssemblyName=%A%
or /p:AssemblyName=${A}
?
Neither of these seem to work (my variable is always empty).
Update: @Tuffwer suggested using the EnvInject plugin. I have been trying, but so far without success. Here's a sample I created to illustrate my original intent:
I want to create a variable which contents will be determined based on a condition applied in one of the build parameters. Then, I want to use that variable as a parameter to the MsBuild command line, using the /p:[Key]=[Value] syntax (which requires the Jenkins MsBuild plugin, if I am not wrong).
I still can't get this to work, now using EnvInject. I need to reference the value of a windows batch variable inside a further build step.
Update II: I turned into Environment Script Plugin, which did the job for me.
回答1:
Tuffwer suggested using the EnvInject plugin, I tried did not succeed attaining what I intended. I edited my post including my EnvInject attempt, but in the meantime went searching again for other solutions.
This time I came across the Environment Script Plugin, which did the job for me.
Steps:
- Mark
Generate environment variables from script
- For each variable you want to "export", you need to issue an
echo [varName]=[value]
statement.
That's all.
My build then creates an assembly named either TRUE.exe or FALSE.exe, depending on the build parameter MyBool
value.
来源:https://stackoverflow.com/questions/43784288/how-to-export-windows-batch-variables-as-build-parameters-to-following-steps-in