Kinook Software Forum

Go Back   Kinook Software Forum > Visual Build Professional > [VBP] General Discussion
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Rate Thread Display Modes
  #1  
Old 12-17-2009, 11:57 AM
dalevine dalevine is online now
Registered User
 
Join Date: 04-23-2009
Posts: 14
Setting environment variables before a remote project is run

I am using one VBP script to execute a VBP script running on a remote VM. Before executing the script I would like to run a batch file, like VCVARS32.BAT so that the environment is set before I start. If I cannot do this then I must use the "Command To Run Before main command" for each external build. This is error prone.

Is there any way to directly establish the enviroment?

Thanks
Reply With Quote
  #2  
Old 12-17-2009, 12:04 PM
kinook kinook is online now
Administrator
 
Join Date: 03-06-2001
Location: Colorado
Posts: 6,034
Make the project that is invoked remotely a stub, which just builds the main project and runs vcvars32.bat before the main command.
Reply With Quote
  #3  
Old 12-18-2009, 08:08 AM
dalevine dalevine is online now
Registered User
 
Join Date: 04-23-2009
Posts: 14
Interesting idea.

So there would be three VBP projects:
1. A VBP on the CI server that invokes the build on the remote VM. This project passes a lot of macro properties to the remote project.

2. The stub, which runs vcvars32.bat, and which retransmits the macro properties to the "real" project.

3. The "real" project, which uses the properties.

Next question: is there any way for the stub to simply pass-thru whatever arguments are passed to it to the "real" VBP without needing to explicitly define each one?

This way I can add properties to VBP1 on the server side and used by VBP3 without being required to modify the stub VBP2?

Thanks so much for you assistance.
Reply With Quote
  #4  
Old 12-18-2009, 10:34 AM
dalevine dalevine is online now
Registered User
 
Join Date: 04-23-2009
Posts: 14
I think I answered my own question. I think this script will work...

For Each macro in vbld_TempMacros()
Builder.LogMessage ( "Found temp macro = " & macro.Name & ", Value= " & macro.Value )
Set objMacro = Application.Project.Macros.Add( macro.Name, macro.Value, ,,True )
objMacro.Value = macro.Value
Next
Reply With Quote
  #5  
Old 12-18-2009, 11:05 AM
kinook kinook is online now
Administrator
 
Join Date: 03-06-2001
Location: Colorado
Posts: 6,034
http://www.kinook.com/Forum/showthre...?threadid=4081
Reply With Quote
  #6  
Old 12-19-2009, 05:13 PM
dalevine dalevine is online now
Registered User
 
Join Date: 04-23-2009
Posts: 14
I'm glad you posted that link, I am using the method shown there.

I ran into a problem marking the temporary variables as environment, as shown here.

"
For Each macro in vbld_TempMacros()
Builder.LogMessage ( "Found temp macro = " & macro.Name & ", Value= " & macro.Value )
macro.AddAsEnvVar = True
Next
"

I chained to the other VBP , using the "Pause at first step for debugging" option. The first time the chained VBP was invoked none of the macros appeared in the chained VBP. If I then exited the project and reran the action, all the macros appeared.

I don't know if the problem only occurs when debugging the project, but I wanted you to know about the bug.
Reply With Quote
  #7  
Old 12-21-2009, 07:56 AM
kinook kinook is online now
Administrator
 
Join Date: 03-06-2001
Location: Colorado
Posts: 6,034
See the 'Create via script' step in the Advanced.bld sample.
Reply With Quote
  #8  
Old 02-01-2011, 06:57 AM
vlad2135 vlad2135 is online now
Registered User
 
Join Date: 02-01-2011
Posts: 6
Can not make to work!

AddSetMacroStep objApp.Project, macro.Name, macro.Value
does not work for me
I'm doing everyting like in the sample and later in the build trying to output macros value from the cmd file:
echo %MY_TEST%

I got nothing.

What am I trying to achieve - I'm trying to separate my global macros into two files - one is global global , and another is specific for each vendor (it will contain stuff like COMPANY_NAME etc...).

So far I was not able to achieve this because Visual Build do not export macros loaded during build to environment.

I load macros like this:
Application.Macros(vbldMacroGlobal).Load "c:\FULLPATH\vendor.macros"

And then iterate all macros:
For Each macro in vbld_AllMacros()
AddSetMacroStep .......
Next

And then run test.cmd:
echo %MY_TEST%

I got ECHO is on.

On the second run everything is OK because new global macros are exported to environment.

So I've tried to restart build from itself, but failed too:
Builder.Stop or Builder.ResetBuildStatus did not help me.

Any advice for my problem?
Reply With Quote
  #9  
Old 02-01-2011, 10:00 AM
kinook kinook is online now
Administrator
 
Join Date: 03-06-2001
Location: Colorado
Posts: 6,034
See attached sample.
Attached Files
File Type: bld envvar.bld (3.6 KB, 1655 views)
Reply With Quote
  #10  
Old 02-01-2011, 11:05 AM
vlad2135 vlad2135 is online now
Registered User
 
Join Date: 02-01-2011
Posts: 6
Thanks a lot for prompt reply. Yes, your sample works but I've managed to modify it according to my requirements and reproduce the problem.

As I've said before, I load all macros from xml file into global macros. After that I iterate output of vbld_AllMacros() function (crucial!!) and add steps to temporary project.
This way it does not work!

But if I load macros from file into temporary macros and iterate vbld_TempMacros(), then everything works just fine!

But I need to import my macros as globals, because they must have lowest priority to be able to be overloaded by project macros.

Anyway, your project, modified and not working, attached to this post. Also source macros file and test cmd file (just for the sake of problem report completeness). You'll only have to remove\replace absolute paths to these files.
Attached Files
File Type: zip envvar2.zip (2.0 KB, 1758 views)
Reply With Quote
  #11  
Old 02-01-2011, 01:03 PM
kinook kinook is online now
Administrator
 
Join Date: 03-06-2001
Location: Colorado
Posts: 6,034
Not sure why you would want to iterate over all macros (including system, which could cause problems). Try using Application.Macros(vbldMacroGlobal) instead.
Reply With Quote
  #12  
Old 02-02-2011, 05:14 AM
vlad2135 vlad2135 is online now
Registered User
 
Join Date: 02-01-2011
Posts: 6
Oh, so easy, thanks a lot! I was using vbld_AllMacros() because I did not know better. Sample code in this thread used vbld_TempMacros(), and I did not figured out that Application.Macros(vbldMacroTemporary) (and, therefore, vbldMacroGlobal) gives exactly the same result!

Thanks a lot for your help, Visual Build is the best!

PS: But I still think that VB could behave better (throw error or something) in the sample I posted

Last edited by vlad2135; 02-02-2011 at 05:21 AM.
Reply With Quote
  #13  
Old 02-02-2011, 09:18 AM
kinook kinook is online now
Administrator
 
Join Date: 03-06-2001
Location: Colorado
Posts: 6,034
The SyncBuild method returns the result of the build. Check it and fail the step accordingly. Enable file logging in the child project to get error information.
http://www.kinook.com/VisBuildPro/Ma...uildmethod.htm
http://www.kinook.com/VisBuildPro/Ma...usproperty.htm
http://www.kinook.com/VisBuildPro/Manual/runscript.htm
http://www.kinook.com/VisBuildPro/Ma...ildlogging.htm
Reply With Quote
  #14  
Old 02-02-2011, 11:28 AM
vlad2135 vlad2135 is online now
Registered User
 
Join Date: 02-01-2011
Posts: 6
I've finally understand the source of the problem.

When ones creates temporary project, it does not have access to macros defined in the original project, it has access to global macros only.

And then, 'Set macro' step fails because my macros loaded from external file requires some macros from project file.
It is strange that I can not force temporary project not to fail by setting objStep.ContinueOnFailure = True and objStep.BuildFailureStepsOnFailure = False in the Function CreateStep - internal build fails anyway.

Anyway, now I have all information required to make this work, the only problem is to decide - are all those new complications and requirements worth it?

I was simply trying to split global macros file into two parts...
Reply With Quote
  #15  
Old 02-02-2011, 12:40 PM
kinook kinook is online now
Administrator
 
Join Date: 03-06-2001
Location: Colorado
Posts: 6,034
See the attached project for another approach to this that doesn't use a separate generated project.
Attached Files
File Type: zip envvar3.zip (1.9 KB, 1721 views)
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



All times are GMT -5. The time now is 05:58 PM.


Copyright © 1999-2023 Kinook Software, Inc.