I'm specifying a label in the "Get Version" property of a TFS 2012 build definition:
Get Version: LMyLabel
However, if MyLabel doesn't exist, the build fails with this error message:
Exception Message: TF14064: Could not find label MyLabel#*. (type LabelNotFoundException)
How can I configure the build to default to the latest code if MyLabel doesn't exist?
You would have to customise the template.
Locate the Get Workspace Activity
Note that it's properties has the GetVersion Argument
Now add a Try Catch Activity, where the current Get Workspace Activity resides
Copy the original Get Workspace Activity to the Try.
Copy the Get Workspace Activity and place it in the catch, Set the catch to Exception
In the Properties of you Get Workspace Activity set the VersionOverride value to be blank.
This should now try and Donwload the source for a label you supply, if that label is not present then the catch should be hit and you should then download the latest code.
This was done on the fly and may need some minor tweeking!
Related
I would like to send the full name of the previous build that was received by using the following:
Run previousBuild = steps.currentBuild.rawBuild.getPreviousBuildInProgress()
in order to send to getItemByFullName as you can see below,
Jenkins.instance.getItemByFullName(previousBuildPath)
I tried to find it in the Run class hudson Documentation with no success.
while printing previousBuild I got the name with the build number like:
previousBuild- > project_neme/build_name #100
But I want to get only the name with no String substring cutting.
You are looking for display name property. Display name is the name given to each build (if you update it during execution) followed by a build number. The display name will only return the build name.
Jenkins.instance.getItemByFullName('JobName').getLastBuild().displayName
Read here
https://javadoc.jenkins.io/hudson/model/Job.html
Is there a way to check if a specific .xml file exists in build directory when TFS build runs?
I'm trying to get a Boolean result true/false based on the result found/not found
I tried creating a variable that would store this result (I'm guessing that is the way to do it). However I get an error when trying to use it.
You can try writing a script to check if the specific file exist, then check in the script and run as Pre-build script in your build process:
e.g.:
$Source = $Env:TF_BUILD_BUILDDIRECTORY
$filename = "*.xml"
if (!(Test-Path "$Source\$filename"))
{
Write-Warning "$filename absent from build directory"
# Write-Error "$filename absent from build directory"
#exit 1
}
Reference Using Environment Variables in Visual Studio 2013 and TFS 2013
The expression editor uses standard VB.NET, so you can call into System.IO.File.Exists(path) to detect whether a file already exists.
Found the solution. I added a new variable "dcMatchedFile" - which is a IEnumerable type. Use this dcMatchedFile as "Result" option for FindMatchingFiles" item (see images below)
Then you can simply use "If" statement to check Any().
In the related TfvcTemplate.12.xaml the solution is to add the build number like so:
<mtbwa:MSBuild CommandLineArguments="[String.Format("/p:SkipInvalidConfigurations=true
/p:BuildNumber={1} {0}", MSBuildArguments, BuildDetail.BuildNumber)]"
In the Git template the arguments have slightly changed, but doing the same results in the following error
Compiler error(s) encountered processing expression
"String.Format("/p:SkipInvalidConfigurations=true /p:BuildNumber={1} {0}",
AdvancedBuildSettings.GetValue(Of String)("MSBuildArguments", String.Empty),
BuildDetail.BuildNumber)".
'Microsoft.TeamFoundation.Build.Client.BuildDetail' is not accessible in
this context because it is 'Friend'.
What is the correct way to expose the BuildNumber in this template?
There's two steps I had to go through to make this work.
https://social.msdn.microsoft.com/Forums/vstudio/en-US/49f11ed9-9fa8-4c20-952a-d39ee7e71051/can-no-longer-user-builddetaildroplocation-for-copydirectory-with-tfs-2013-using-build-process?forum=tfsbuild
Within the same template you modified in step 1 click on the "Run MSBuild" activity, view properties and open "CommandLineArguments". I'm using OctoPack for Octopus Deploy so here's what my arguments look like:
String.Format("/p:SkipInvalidConfigurations=true /p:BuildNumber={1} {0}
/p:OctoPackPackageVersion={1}", AdvancedBuildSettings.GetValue(Of
String)("MSBuildArguments", String.Empty), BuildDetail.BuildNumber)
As you can see, BuildNumber is specified there so you can just remove the Octopus property I added. Finally within your msbuild file (.csproj for example) you'd use build number like so $(BuildNumber)
From within Visual Studio I try to commit to a tfs repository. I can use the Server Browser and update my sources. But when I click onto "pending changes" I receive the following error:
System.ComponentModel.Composition.CompositionException: The
composition produced a single composition error. The root cause is
provided below. Review the CompositionException.Errors property for
more detailed information.
1) Cannot create an instance of type
'Microsoft.TeamFoundation.VersionControl.Controls.LabelSaveException'
because a constructor could not be selected for construction. Ensure
that the type either has a default constructor, or a single
constructor marked with the
'System.ComponentModel.Composition.ImportingConstructorAttribute'.
Resulting in: Cannot activate part
'Microsoft.TeamFoundation.VersionControl.Controls.LabelSaveException'.
Element:
Microsoft.TeamFoundation.VersionControl.Controls.LabelSaveException
--> Microsoft.TeamFoundation.VersionControl.Controls.LabelSaveException
Resulting in: Cannot get export
'Microsoft.TeamFoundation.VersionControl.Controls.LabelSaveException
(ContractName="Microsoft.TeamFoundation.Controls.ITeamExplorerSection")'
from part
'Microsoft.TeamFoundation.VersionControl.Controls.LabelSaveException'.
Element:
Microsoft.TeamFoundation.VersionControl.Controls.LabelSaveException
(ContractName="Microsoft.TeamFoundation.Controls.ITeamExplorerSection")
--> Microsoft.TeamFoundation.VersionControl.Controls.LabelSaveException
at
System.ComponentModel.Composition.Hosting.CompositionServices.GetExportedValueFromComposedPart(ImportEngine
engine, ComposablePart part, ExportDefinition definition) at
System.ComponentModel.Composition.Hosting.CatalogExportProvider.GetExportedValue(CatalogPart
part, ExportDefinition export, Boolean isSharedPart) at
System.ComponentModel.Composition.Hosting.CatalogExportProvider.CatalogExport.GetExportedValueCore()
at System.ComponentModel.Composition.Primitives.Export.get_Value()
at
System.ComponentModel.Composition.ExportServices.GetCastedExportedValue[T](Export
export) at
System.ComponentModel.Composition.ReflectionModel.ExportFactoryCreator.LifetimeContext.GetExportLifetimeContextFromExport[T](Export
export) at
System.ComponentModel.Composition.ReflectionModel.ExportFactoryCreator.<>c__DisplayClass72.<CreateStronglyTypedExportFactoryOfTM>b__6()
at System.ComponentModel.Composition.ExportFactory1.CreateExport()
at
Microsoft.TeamFoundation.Controls.WPF.TeamExplorer.Framework.TeamExplorerSectionHost.Create()
I CAN still check in my changes, but the "comment" area is missing. How to solve this?
(UPDATE): I receive the same error when I try to display the "Changeset Details"
But no Error when displaying the History
We are trying to have ReSharper's cleanup code run on TFS Checkin. Ideally, when you right click on the solution / project and select Source Control > Check in all the files in the "Included Changes" should run cleanup code. I've got the custom checkin policy to work to some extent, works fine if you select a single file to check in but when you select the solution or project, it tries to run cleanup code on the entire solution / project and not just the files selected in TFS Pending Changes "Include Changes".
I'm running VS 2013 with R# 8.2. My policy evaluate code:
public override PolicyFailure[] Evaluate()
{
if (PendingCheckin.Policies.EvaluationState == PolicyEvaluationState.Unevaluated)
{
DTE2 dte = PendingCheckin.GetService(typeof (DTE)) as DTE2;
foreach (EnvDTE.Document doc in dte.Documents)
{
doc.DTE.ExecuteCommand("ReSharper_SilentCleanupCode");
}
}
return new PolicyFailure[0];
}
I don't think this only applies to ReSharper, executing "Edit.FormatDocument" here would most likely run on all files as well.
Is there a way to run ExecuteCommand on only 1 file / document?
It seems like
PendingCheckin.GetService(typeof (DTE))
only gets files that are open in the Visual Studio editor not all the files that are in the "Include Changes" list. I can get a list of PendingChange through
PendingCheckin.PendingChanges.CheckedPendingChanges
But I don't know how to execute a command on PendingChange. Recommendations here would help
PS: I've read that the check in policy is meant to be used for checking documents only, however this workflow is what we need.