views:

3665

answers:

7

When calling external processes like MSBuild cruise control sets environment variables. One of values is CCNetLabel. it holds the value of the current projects label. I want to use the same values in ccnet config itself but when I try ccnet config has a problem. I get the following error:

[CCNet Server:ERROR] INTERNAL ERROR: Reference to unknown symbol CCNetLabel
----------
ThoughtWorks.CruiseControl.Core.Config.Preprocessor.EvaluationException: Reference to unknown symbol CCNetLabel
at ThoughtWorks.CruiseControl.Core.Config.Preprocessor.ConfigPreprocessorEnvironment._GetConstantDef(String name)
at ThoughtWorks.CruiseControl.Core.Config.Preprocessor.ConfigPreprocessorEnvironment.eval_text_constant(String name)

.....

----------

I actually want to append the CCNetLabel to another variable so I need to access the property in ccnet.config.

is there a different way to reference these variables?

+1  A: 

There is no way of accessing these environment variables inside CCNET configuration. I think almost anybody who configured CCNET (including myself) has tried to do so. This feature has been requested often, but it hasn't been implemented yet.

If you want access to CCNetWorkingDirectory or CCNetArtifactDirectory there is a workaround:

<cb:define name="project.workingDirectory">c:/foo</cb:define>
<cb:define name="project.artifactDirectory">c:/bar</cb:define>
<project>
  <workingDirectory>$(project.workingDirectory)</workingDirectory>
  <artifactDirectory>$(project.artifactDirectory)</artifactDirectory>
  ...
</project>

But I'm not aware of a solution for accessing CCNetLabel. Sorry, I don't have better news.

The Chairman
A: 

I'm having the same problem. It's a real pain not being able to do this :( I wanted to extract common configuration blocks into include files and customise them using the $(CCNetProject) variable. Defining my own because variables won't work because I have several projects in one ccnet.config and can't redefine the project variable for each one.

Mark
+3  A: 

The following articles should be able to help you. You may be able to use cb:scope, or defining your whole project in a cb:define and pass the project name in.

-Good luck-

http://confluence.public.thoughtworks.org/display/CCNET/Configuration+Preprocessor

http://ferventcoder.com/archive/2009/05/21/uppercut---automated-builds---cruisecontrol.net-integration.aspx

Adam
+1 - this is great and solves a lot of problems! Thanks.
Andrew Siemer
+3  A: 

The following can be used in config file in ccnet version 1.5 < cb:define buildversion="$[$CCNetLabel]" />

Thinker
This works. I put this one after the labeller type. and used $(buildversion) and it got substituted correctly.
Pradeep
Does not work for me
The Chairman
+3  A: 

We had a need to do this too, and found that we could use Replacement Dynamic Values, introduced in CruiseControl.NET 1.5, to access the CCNetLabel from within ccnet.config.

For example, the dynamicValues block in this snippet:

  <buildpublisher>
    <sourceDir>C:\ccnet_projects\Installer\bin\x86\Release</sourceDir>
    <dynamicValues>
      <replacementValue property="publishDir">
        <format>C:\builds\installers\{0}\x86</format>
        <parameters>
          <namedValue name="$CCNetLabel" value="Default" />
        </parameters>
      </replacementValue>
    </dynamicValues>
    <useLabelSubDirectory>false</useLabelSubDirectory>
  </buildpublisher>

Produces a publishDir path containing the CCNetLabel value on the fly:

  <buildpublisher>
    <sourceDir>C:\ccnet_projects\Installer\bin\x86\Release</sourceDir>
    <publishDir>C:\builds\installers\1.0.2.120\x86</publishDir>
    <useLabelSubDirectory>false</useLabelSubDirectory>
  </buildpublisher>      

(Note that for this particular example, useLabelSubDirectory is set to false to avoid appending the CCNetLabel to the publishDir path.)

Darryl
This worked for me. Thanks!
sectrean
A: 

I tried to do this as well and just ended up using a NANT script, where I can get to CCNetLabel as an environment variabl like so:

  <property name="version.build" value="${environment::get-variable('CCNetLabel')}"/>
Igor Zevaka
A: 

if using version 1.5 then you can directly specify $(CCNetLabel) in the msbuild task

 
<msbuild>
 <executable>C:\WINDOWS\Microsoft.NET\Framework\v3.5\MSBuild.exe</executable>
 <workingDirectory>C:\\TestApp\WindowsFormsApplication1</workingDirectory>
 <projectFile>WindowsFormsApplication1.sln</projectFile>
 <buildArgs>/p:Configuration=Debug /p:Platform="Any Cpu" /p:AssemblyVersion=$(CCNetLabel) </buildArgs>
 <targets>build</targets>
 <logger>C:\Program Files\CruiseControl.NET\server\ThoughtWorks.CruiseControl.MsBuild.dll</logger>
</msbuild>
   
   
kazim mehdi