Release Management sets builds to Retain Indefinitely

北慕城南 提交于 2019-12-04 11:11:28

As of RM for TFS 2013.3, this is not possible. According to Teodora Stanev on this post, this is by design.

Feel free to post a request on the Visual Studio UserVoice site

I have a solution to this, rather a workaround.

I have customized our build definition with the following Sequence (for TFS 2013) at the beginning of the workflow. This sequence grabs all succeeded builds for the definition and clears the Retain Indefinitely.

This means only the last ran build will have the flag. It also means you can't set a build as retain indefinitely for that definition. That is OK for us in this specific situation as it is for continuous integration builds (like the poster).

Edit: Changing to include All builds (was Successful only) as a build is marked as failed and still set to retain indefinitely if the build succeeds but release fails.

<Sequence DisplayName="Cleanup: Clear 'Retain Indefinitely' from previous builds">
  <Sequence.Variables>
    <Variable x:TypeArguments="mtbc:IBuildDetail" Name="localBuildDetail" />
    <Variable x:TypeArguments="mtbc:IBuildDetailSpec" Name="localBuildDetailSpec" />
    <Variable x:TypeArguments="mtbc:IBuildQueryResult" Name="localBuildQueryResult" />
  </Sequence.Variables>
  <mtbwa:GetBuildDetail DisplayName="Get the Build Details" Result="[localBuildDetail]" />
  <InvokeMethod DisplayName="Create the Build Detail Spec" MethodName="CreateBuildDetailSpec">
    <InvokeMethod.TargetObject>
      <InArgument x:TypeArguments="mtbc:IBuildServer">[localBuildDetail.BuildServer]</InArgument>
    </InvokeMethod.TargetObject>
    <InvokeMethod.Result>
      <OutArgument x:TypeArguments="mtbc:IBuildDetailSpec">[localBuildDetailSpec]</OutArgument>
    </InvokeMethod.Result>
    <InArgument x:TypeArguments="x:String">[localBuildDetail.TeamProject]</InArgument>
  </InvokeMethod>
  <Assign DisplayName="Setting Query Order Descending">
    <Assign.To>
      <OutArgument x:TypeArguments="mtbc:BuildQueryOrder">[localBuildDetailSpec.QueryOrder]</OutArgument>
    </Assign.To>
    <Assign.Value>
      <InArgument x:TypeArguments="mtbc:BuildQueryOrder">FinishTimeDescending</InArgument>
    </Assign.Value>
  </Assign>
  <Assign DisplayName="Setting Build Definition">
    <Assign.To>
      <OutArgument x:TypeArguments="x:String">[localBuildDetailSpec.DefinitionSpec.Name]</OutArgument>
    </Assign.To>
    <Assign.Value>
      <InArgument x:TypeArguments="x:String">[localBuildDetail.BuildDefinition.Name]</InArgument>
    </Assign.Value>
  </Assign>
  <Assign DisplayName="Setting Query Type to All Builds">
    <Assign.To>
      <OutArgument x:TypeArguments="mtbc:BuildStatus">[localBuildDetailSpec.Status]</OutArgument>
    </Assign.To>
    <Assign.Value>
      <InArgument x:TypeArguments="mtbc:BuildStatus">All</InArgument>
    </Assign.Value>
  </Assign>
  <InvokeMethod DisplayName="Getting Previous Builds" MethodName="QueryBuilds">
    <InvokeMethod.TargetObject>
      <InArgument x:TypeArguments="mtbc:IBuildServer">[localBuildDetail.BuildServer]</InArgument>
    </InvokeMethod.TargetObject>
    <InvokeMethod.Result>
      <OutArgument x:TypeArguments="mtbc:IBuildQueryResult">[localBuildQueryResult]</OutArgument>
    </InvokeMethod.Result>
    <InArgument x:TypeArguments="mtbc:IBuildDetailSpec">[localBuildDetailSpec]</InArgument>
  </InvokeMethod>
  <ForEach DisplayName="Loop through all builds and undo 'Retain Indefinitely' set by Release Management."
           x:TypeArguments="mtbc:IBuildDetail"
           Values="[localBuildQueryResult.Builds]">
    <ActivityAction x:TypeArguments="mtbc:IBuildDetail">
      <ActivityAction.Argument>
        <DelegateInArgument x:TypeArguments="mtbc:IBuildDetail" Name="localBuild" />
      </ActivityAction.Argument>
      <Sequence DisplayName="Checking Build Next Build">
        <If Condition="[localBuild.KeepForever = True]" DisplayName="If the build is marked 'Retain Indefinitely'">
          <If.Then>
            <Sequence DisplayName="Updating Build Details">
              <Assign DisplayName="Setting KeepForver to false">
                <Assign.To>
                  <OutArgument x:TypeArguments="x:Boolean">[localBuild.KeepForever]</OutArgument>
                </Assign.To>
                <Assign.Value>
                  <InArgument x:TypeArguments="x:Boolean">false</InArgument>
                </Assign.Value>
              </Assign>
              <InvokeMethod DisplayName="Saving Build Details" MethodName="Save">
                <InvokeMethod.TargetObject>
                  <InArgument x:TypeArguments="mtbc:IBuildDetail">[localBuild]</InArgument>
                </InvokeMethod.TargetObject>
              </InvokeMethod>
            </Sequence>
          </If.Then>
        </If>
      </Sequence>
    </ActivityAction>
  </ForEach>
</Sequence>

Release Management follows the model of Lab Management, whereby if a Build is deployed it is retained indefinately.

This allows you to alter the build quality etc as the build is verified and signed off, you may then promote / do whatever with that build without fear that it will be deleted by the retention policy.

you just need to do it as a daily / weekly / monthly admin task, choose your build from the drop down list in the build screen and then show all.

highlight all of the builds and then click the remove retention button.

if it bothers you that much you could write a script to find all of the builds and then remove the lock.

psudo:

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