1

我正在尝试为我们的应用程序设置构建服务器。在进行强制构建时,我想使用参数来确定要构建的内容。下面我的设置可以在 DEV 中运行,主要是因为 if 语句是设置的一个片段。无论我选择 QA 还是 UAT,它总是错误的。以前有没有人尝试过用 Cruisecontrol.net 做到这一点?

<cb:define name="ParametersTemplate">
    <parameters>
      <selectParameter>
        <name>Target</name>
        <display>Target to Build</display>
        <description>Which target do you want to build?</description>
        <default>DEV</default>
        <allowedValues>
          <value name="DEV">DEV</value>
          <value name="QA">QA</value>
          <value name="UAT">UAT</value>
        </allowedValues>
      </selectParameter>
      <textParameter>
        <name>Branch</name>
        <display>Branch Name:</display>
        <description>Name of the branch you want to build?</description>
        <default>_DEV</default>
        <minimum>8</minimum>
        <maximum>255</maximum>
        <required>true</required>
      </textParameter>
    </parameters>
  </cb:define>

<cb:define name="ProjectTemplate">
    <workingDirectory>$(WorkingDir)\$(ProjectName)</workingDirectory>
    <artifactDirectory>$(ArtifactsDir)\$(ProjectName)</artifactDirectory>
    <sourcecontrol type="svn" cleanCopy="true">
      <workingDirectory>$(WorkingDir)\$(ProjectName)</workingDirectory>
      <cb:if expr="$[Branch] == 'QA' || $[Branch] == 'UAT'">
        <trunkUrl>$(SVNLocation)/$(ProjectSvnReleaseLocation)/$[Branch]</trunkUrl>
      </cb:if>
      <cb:else>
         <trunkUrl>$(SVNLocation)/$(ProjectSvnDevLocation)</trunkUrl>            
      </cb:else>
      <cb:SVNCredentials/>
    </sourcecontrol>
    <labeller type="svnRevisionLabeller">
      <cb:LabelCommon />
      <cb:if expr="'$[Branch]'=='QA' || '$[Branch]'=='UAT'">
        <url>$(SVNLocation)/$(ProjectSvnReleaseLocation)/$[Branch]</url>
      </cb:if>
      <cb:else>
        <url>$(SVNLocation)/$(ProjectSvnDevLocation)</url>
      </cb:else>
      <cb:SVNCredentials/>
    </labeller>
    <tasks>
      <nant>
        <targetList>
          <target>$(ProjectName)</target>
        </targetList>
        <cb:NantCommon />
      </nant>
    </tasks>
    <cb:ParametersTemplate/>
  </cb:define>

我查找并发现的一件事是替换变量,但我不确定如何将它们用于这样的设置。

任何帮助将不胜感激。

4

3 回答 3

2

The left side variables in your first cb:if expression need to be surrounded by single quotes, like you do in the second cb:if expression, like so:

  <cb:if expr="'$[Branch]' == 'QA' || '$[Branch]' == 'UAT'">
    <trunkUrl>$(SVNLocation)/$(ProjectSvnReleaseLocation)/$[Branch]</trunkUrl>
  </cb:if>
  <cb:else>
     <trunkUrl>$(SVNLocation)/$(ProjectSvnDevLocation)</trunkUrl>            
  </cb:else>
于 2013-04-12T00:57:24.213 回答
1

In my humble opinion, it's not a good idea to try and change the svn url like that. Even if you get it to work, various other things might break. I'd go with three different projects instead, using a common template to share the rest of the configuration.

于 2012-10-10T12:30:52.640 回答
1

You are confusing two concepts here. cb:if is part of the preprocessor and is used when parsing the configuration, before any project is run. If you want to act depending on the value of a dynamic value, you should use the conditional task with a compare value condition :

http://www.cruisecontrolnet.org/projects/ccnet/wiki/Conditional_Task

http://www.cruisecontrolnet.org/projects/ccnet/wiki/Compare_Values_Condition

This will work when running a project, inside a task. However, for your case, this will not help because you want to change a value inside a source control block, which is not supported the way you want it. What you could do, though, is have the branch name as the value of the parameter :

http://www.cruisecontrolnet.org/projects/ccnet/wiki/SelectParameter

于 2013-10-19T20:48:46.693 回答