How to run msbuild from a Python script?

1,038 views
Skip to first unread message

David Aldrich

unread,
May 28, 2014, 10:56:19 AM5/28/14
to jenkins...@googlegroups.com

Hi

 

I have a Jenkins job that builds a Visual Studio project in multiple configurations using msbuild.  I currently have multiple build steps in the job – one Windows batch command step for each call of msbuild.

 

I want to replace these steps with a single Python script, which will be easier to configure and that can be put under version control.

 

My difficulty is that I don’t know much Python and I am struggling to run vcvarsall.bat and msbuild in a single subprocess.

 

I know this is more of a Python question than a Jenkins question, but I thought that someone here may have faced the same problem and may be able to share some code.

 

Any help would be appreciated.

 

Best regards

 

David

corneil....@gmail.com

unread,
May 28, 2014, 11:23:15 AM5/28/14
to jenkins...@googlegroups.com
When vcvarsall.bat executes it sets environment variables, but they only valid within the command shell in which it is executed and when that shell terminates the environment variables are gone.
Your python will be creating a command shell each time it executes vcvarsall.bat and then a process for msbuild which means msbuild doesn't know about the environmental variables.

You will need to do some work to determine the values of those environmental settings.
Then you can configure you Jenkins Master, slave or job with the appropriate environmental settings and launch msbuild as different step.

Or you can then write the Python to set the environment each time it creates the process for msbuild step based on what you have discovered.
 
Alternatively you will need to create batch/cmd files that invoke vcvarsall.bat and before the relevant msbuild step.


--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-use...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages