4

How can I set environment variable in Cruisecontrol?

If I try to do it like this:

<exec command="set PATH="
                workingdir="d:\AppLiteNew\Projects\"
                args = "%PATH%;D:\QtSDK\mingw\bin\"/> 

it does not work, all I got is:

[cc]Dec-13 13:30:28 ExecBuilder - Could not execute command: set PATH= with arguments: %PATH%;D:\QtSDK\mingw\bin\

oers
  • 18,436
  • 13
  • 66
  • 75
unresolved_external
  • 1,930
  • 5
  • 30
  • 65

2 Answers2

7

Firstly, you use the exec command wrong

The command is set and its argument should be PATH=%PATH%;D:\QtSDK\mingw\bin\

This should work:

<exec command="set"
  workingdir="d:\AppLiteNew\Projects\"
  args = "PATH=%PATH%;D:\QtSDK\mingw\bin\"/> 

Secondly, it won't have an effect

The Path you set, will only be available to the shell/command that is executed by invoking exec. After the call it will not be available to further commands /executions.
You didn't state what use case you have or where you need the variable, therefore I can only guess, what you could do. You could do the following:

  1. Set the Path directly in Windows, for everything (if that is okay)
  2. Edit the batch file, that starts cruisecontrol and set the PATH there
  3. Create a batch file for the command that needs the PATH and set the PATH there.
  4. Some ant-tasks allow to specify environment variables for them
oers
  • 18,436
  • 13
  • 66
  • 75
  • @unresolved_external okay maybe you should clarify, what you need to do. The exec task will probably only set the this PATH in its own shell, this call will have no effect on the system. Therefore it will not be available for any further calls /executions. If you need this value globally you should set it in windows, or include it in a batch script, which will execute everything you need. – oers Dec 13 '11 at 11:50
  • ok, so make question is how could I set an environment variable in cruisecontrol tool? – unresolved_external Dec 13 '11 at 11:55
  • @unresolved_external I updated the question, but is very hard to give real help, because it is not clear which task or execution in cruisecontrol needs the PATH set. – oers Dec 13 '11 at 13:32
  • thanks, for the edit, now I am facing another problem I have to send report by email, for example I am looking on tag in cruisecontrol documantion. But I dont see destination mail in as mandatory option, actually I dont this filed at all. can you tell me pls< where I have to write destionation mail? thanks on advance. – unresolved_external Dec 13 '11 at 14:39
  • this is a completely new question :) Cruisecontrol sends emails to users who made a change to the code, see the map tags of [email](http://cruisecontrol.sourceforge.net/main/configxml.html#email). But feel fry to open a new question for that. – oers Dec 13 '11 at 14:51
  • one more really related question, is command exec can execute any commnad form command line? because when i am trying to use it I got the same error, that was mentioned in a very first question – unresolved_external Dec 13 '11 at 14:59
  • @unresolved_external any command that can be executed in your system should work [see the doc](http://cruisecontrol.sourceforge.net/main/configxml.html#exec) – oers Dec 13 '11 at 16:08
  • That's ridiculous, i should just be able to source the C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\VsDevCmd.bat ..you think i wanna recreate those 100's of lines in each :( – Brunis Oct 17 '18 at 08:27
2

In CruiseControl.net you can set them in the configuration of the task. They go in an environment block:

<environment>
    <variable name="MyVar2" value="Var2Value" />
</environment>

Here's a full sample:

<msbuild>
    <executable>C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\MSBuild.exe</executable>
    <workingDirectory>C:\dev\ccnet</workingDirectory>
    <projectFile>CCNet.sln</projectFile>
    <buildArgs>/p:Configuration=Debug /v:diag</buildArgs>
    <targets>Build;Test</targets>
    <timeout>900</timeout>
    <logger>C:\Program Files\CruiseControl.NET\server\ThoughtWorks.CruiseControl.MsBuild.dll</logger>
    <environment>
        <variable name="MyVar2" value="Var2Value" />
    </environment>
 </msbuild>
Martynnw
  • 10,625
  • 5
  • 28
  • 27