CruiseControl.NET: using $(CCNetLabel ) inside ccnet.config file

社会主义新天地 提交于 2019-11-27 10:54:30

问题


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:


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.)




回答2:


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




回答3:


I think Darryl's answer is the best approach to solve this problem in CCNET 1.5. Just two comments about the answer:

  • This is the right link to ccnet docs about Dynamic Parameters.
  • As you can read in the docs, there is a shortcut to obtain just the value of the integration property you are looking for using the syntax $[$Integration_Property]. In your case, using $[$CCNetLabel] would work.



回答4:


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.




回答5:


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




回答6:


I've solved this by adding an msbuild task in the publisher section (including the CCNetLabel in the path)

<msbuild>
    <executable>c:\Windows\Microsoft.NET\Framework\v4.0.30319\MSBuild.exe</executable>
    <workingDirectory>C:\Path\WebApp</workingDirectory>
    <projectFile>WebApp.csproj</projectFile>
    <dynamicValues>
        <replacementValue property="buildArgs">
            <format>/noconsolelogger /v:quiet /p:Configuration=Release /p:WebProjectOutputDir=c:\Publish\WebApp\{0}\ /p:OutDir=c:\Publish\WebApp\{0}\bin\</format>
            <parameters>
                <namedValue name="$CCNetLabel" value="Default" />
            </parameters>
        </replacementValue>
    </dynamicValues>                    
    <targets>ResolveReferences;_CopyWebApplication</targets>
    <timeout>600</timeout>              
</msbuild>



回答7:


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>
   
   



回答8:


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')}"/>


来源:https://stackoverflow.com/questions/1563362/cruisecontrol-net-using-ccnetlabel-inside-ccnet-config-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!