3

I want Jenkins to run "Execute Windows batch command" enter image description here

After run this, this command make a output with multiple lines. These rows will be used in next build step so that I want to save these to my Jenkins environment variables.

How can I save these value? If there is other way, let me know. Thanks!

3 Answers 3

7

Because each Execute Window Batch or Execute shell build step run in seperate sandbox, so any environment variable exported inside them will be destoried once step finish.

If you want those environment varabiles can be used accross step, you have to export then into file, then read the file back.

Step 1, generate a plain file with key = value pattern by Execute window batch or 'Execute shell'

Step 2, add a Inject environment variable build step, and specify above generated file, once this build step complete, those keys will be exportedinto the job building's environment variables set.

Step 3, you can use them by ${key} in windows batch or linux shell in subsequent build steps and any post actions

enter image description here

Sign up to request clarification or add additional context in comments.

Comments

0

Make sure when running this as a Windows Batch command to call environment variables by Windows convention. At least that's what I had to do to get things to work.

echo %username%

echo %password%

Comments

0

It works well only when the variable value assignment is not enclosed with quotes.

echo username=abc >> env.property
echo password=123 >> env.property

Otherwise, the environment variables set as follows: "username and "password value set as follows abc" and 123"

Starting quote appends with variable name and ending quote appends with variable value at last

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.