21

调用 MSBuild 巡航控制等外部进程时会设置环境变量。值之一是 CCNetLabel。它保存当前项目标签的值。我想在 ccnet config 本身中使用相同的值,但是当我尝试 ccnet config 时出现问题。我收到以下错误:

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

.....

----------

我实际上想将 CCNetLabel 附加到另一个变量,所以我需要访问 ccnet.config 中的属性。

有没有不同的方法来引用这些变量?

4

8 回答 8

21

我们也需要这样做,并发现我们可以使用CruiseControl.NET 1.5 中引入的Replacement Dynamic Values从 ccnet.config中访问CCNetLabel 。

例如,此代码段中的dynamicValues块:

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

动态生成包含CCNetLabel值的publishDir路径:

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

(请注意,对于这个特定示例,useLabelSubDirectory设置为 false 以避免将CCNetLabel附加到publishDir路径。)

于 2010-04-08T22:49:15.923 回答
15

在 ccnet 1.5 版本的配置文件中可以使用以下内容 < cb:define buildversion="$[ $CCNetLabel ]" />

于 2010-02-19T21:50:43.847 回答
9

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.
于 2011-01-20T15:01:37.700 回答
5

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.

于 2009-10-14T06:57:38.683 回答
5

下面的文章应该可以帮到你。您可以使用cb:scope,或在 a 中定义整个项目cb:define并将项目名称传入。

-祝你好运-

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

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

于 2009-11-13T14:23:27.483 回答
3

我已经通过在发布者部分添加一个 msbuild 任务解决了这个问题(包括CCNetLabel在路径中)

<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>
于 2011-02-11T09:15:57.500 回答
2

如果使用 1.5 版,那么您可以直接在 msbuild 任务中指定 $(CCNetLabel)

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

于 2010-07-08T11:56:23.010 回答
1

我也尝试过这样做,最后使用了一个 NANT 脚本,我可以CCNetLabel像这样作为环境变量访问:

  <property name="version.build" value="${environment::get-variable('CCNetLabel')}"/>
于 2010-05-10T08:11:25.800 回答