protected override void Execute(CodeActivityContext context) { #region Workflow Arguments // The TFS source location of the file to get var fileToGet = context.GetValue(FileToGet); // The current workspace - used to create a new workspace for the get var workspace = context.GetValue(Workspace); // The local build directory var buildDirectory = context.GetValue(BuildDirectory); var destinationSubfolderName = context.GetValue(DestinationSubfolderName); #endregion // File and path var versionFileDirectory = string.Format("{0}\\{1}", buildDirectory, destinationSubfolderName); var filename = Path.GetFileName(fileToGet); if (filename == null) { throw new ArgumentException("Filename must not be null"); } var fullPathToFile = Path.Combine(versionFileDirectory, filename); // Write to the log context.WriteBuildMessage(string.Format("Getting file from Source: {0}", fileToGet), BuildMessageImportance.High); // Create workspace and working folder var tempWorkspace = workspace.VersionControlServer.CreateWorkspace("NuGetterTemp"); var workingFolder = new WorkingFolder(fileToGet, fullPathToFile); // Map the workspace tempWorkspace.CreateMapping(workingFolder); // Get the file var request = new GetRequest(new ItemSpec(fileToGet, RecursionType.None), VersionSpec.Latest); var status = tempWorkspace.Get(request, GetOptions.GetAll | GetOptions.Overwrite); if (!status.NoActionNeeded) { foreach (var failure in status.GetFailures()) { context.WriteBuildMessage(string.Format("Failed to get file from source: {0} - {1}", fileToGet, failure.GetFormattedMessage()), BuildMessageImportance.High); } } // Return the value back to the workflow context.SetValue(FullPathToFile, fullPathToFile); // Get rid of the workspace tempWorkspace.Delete(); }
protected override void Execute(CodeActivityContext context) { #region Workflow Arguments var switchInvokePowerShell = SwitchInvokePowerShell.Get(context); var powerShellScriptPath = PowerShellScriptPath.Get(context); var nuGetExeFilePath = NuGetExeFilePath.Get(context); var nuSpecFilePath = NuSpecFilePath.Get(context); var basePath = BasePath.Get(context); var outputDirectory = OutputDirectory.Get(context); var version = Version.Get(context); var switchInvokePush = SwitchInvokePush.Get(context); var apiKey = ApiKey.Get(context); var pushDestination = PushDestination.Get(context); var additionalOptions = AdditionalOptions.Get(context); #endregion var resultMessages = SummarizePropertyValues(switchInvokePowerShell, powerShellScriptPath, nuGetExeFilePath, nuSpecFilePath, basePath, outputDirectory, version, switchInvokePush, apiKey, pushDestination, additionalOptions); for (var i = 0; i < resultMessages.Length - 1; i++) { // Write to the log context.WriteBuildMessage(resultMessages[i], BuildMessageImportance.High); } }
/// <summary> /// Searches an XML file with an XPath expression /// </summary> /// <param name="context"></param> protected override void Execute(CodeActivityContext context) { // get the value of the XPathExpression var xpathExpression = context.GetValue(XPathExpression); // get the value of the FilePath var filePath = context.GetValue(FilePath); // get the value of the Namespace var xmlNamespace = context.GetValue(XmlNamespace); // get the value of the Namespace var xmlNamespacePrefix = context.GetValue(XmlNamespacePrefix); string elementValue; try { elementValue = GetXmlElementValue(filePath, xpathExpression, xmlNamespace, xmlNamespacePrefix); } catch (FileNotFoundException fileNotFoundException) { context.WriteBuildMessage(string.Format("In XmlGetElement - {0} - File: {1}", fileNotFoundException.Message, filePath), BuildMessageImportance.High); throw; } // return the value ElementValue.Set(context, elementValue); }
protected override void Execute(CodeActivityContext context) { #region Workflow Arguments // This will be the api key or a path to the file with the key in it (or blank) var versionPatternOrSeedFilePath = VersionPatternOrSeedFilePath.Get(context); // The local build directory var packageId = PackageId.Get(context); var sourcesDirectory = SourcesDirectory.Get(context); #endregion string versionPattern; try { versionPattern = ExtractVersion(versionPatternOrSeedFilePath, packageId, QueryPackageId, sourcesDirectory); } catch (ArgumentException) { versionPattern = ExtractVersion(versionPatternOrSeedFilePath, packageId, QuerySolutionName, sourcesDirectory); } // Write to the log context.WriteBuildMessage(string.Format("Version Pattern: {0}", versionPattern), BuildMessageImportance.Normal); // Return the value back to the workflow context.SetValue(VersionPattern, versionPattern); }
// If your activity returns a value, derive from CodeActivity<TResult> // and return the value from the Execute method. protected override void Execute(CodeActivityContext context) { var dropFolder = DropFolder.Get(context); var sourcesFolder = SourcesFolder.Get(context); var binariesFolder = BinariesFolder.Get(context); var powerShellScriptFilepath = PowerShellScriptFilepath.Get(context); var nuGetPrePackageFolder = NuGetPrePackageFolder.Get(context); context.WriteBuildMessage(string.Format("powerShellScriptFilepath: {0}", powerShellScriptFilepath), BuildMessageImportance.High); context.WriteBuildMessage(string.Format("dropFolder: {0}", dropFolder), BuildMessageImportance.High); context.WriteBuildMessage(string.Format("binariesFolder: {0}", binariesFolder), BuildMessageImportance.High); context.WriteBuildMessage(string.Format("sourcesFolder: {0}", sourcesFolder), BuildMessageImportance.High); // Call the PowerShell script var result = ExecutePowerShellScript(powerShellScriptFilepath, dropFolder, binariesFolder, sourcesFolder, nuGetPrePackageFolder); // Return the value back to the workflow context.SetValue(Result, result); }
public bool RunNuGetProcess(string nuGetFilePath, string arguments, CodeActivityContext context) { var stopwatch = new Stopwatch(); stopwatch.Start(); var proc = new Process { StartInfo = { FileName = nuGetFilePath, Arguments = arguments, UseShellExecute = false, CreateNoWindow = true, RedirectStandardError = true } }; proc.Start(); var errorOutput = proc.StandardError.ReadToEnd(); // Block for now but force release of the process after 5 minutes - Just in case NuGet fails to return // otherwise it will return as soon as NuGet is done. var result = proc.WaitForExit(300000); stopwatch.Stop(); if (context != null) { if (!string.IsNullOrWhiteSpace(errorOutput)) { result = false; context.WriteBuildMessage(string.Format("Error reported in the NuGet Process: {0}", errorOutput), BuildMessageImportance.High); } context.WriteBuildMessage(string.Format("NuGet Process execution time: {0}", stopwatch.Elapsed.Seconds), BuildMessageImportance.High); } return(result); }
public bool RunNuGetProcess(string nuGetFilePath, string arguments, CodeActivityContext context) { var stopwatch = new Stopwatch(); stopwatch.Start(); var proc = new Process { StartInfo = { FileName = nuGetFilePath, Arguments = arguments, UseShellExecute = false, CreateNoWindow = true, RedirectStandardError = true } }; proc.Start(); var errorOutput = proc.StandardError.ReadToEnd(); // Block for now but force release of the process after 5 minutes - Just in case NuGet fails to return // otherwise it will return as soon as NuGet is done. var result = proc.WaitForExit(300000); stopwatch.Stop(); if (context != null) { if (!string.IsNullOrWhiteSpace(errorOutput)) { result = false; context.WriteBuildMessage(string.Format("Error reported in the NuGet Process: {0}", errorOutput), BuildMessageImportance.High); } context.WriteBuildMessage(string.Format("NuGet Process execution time: {0}", stopwatch.Elapsed.Seconds), BuildMessageImportance.High); } return result; }
/// <summary> /// Searches an XML file with an XPath expression /// </summary> /// <param name="context"></param> protected override void Execute(CodeActivityContext context) { // get the value of the XPathExpression var fileNamePattern = FileNamePattern.Get(context); // get the value of the FilePath var searchFolder = SearchFolder.Get(context); var filePath = FindFile(fileNamePattern, searchFolder); context.WriteBuildMessage(string.Format("Path found: {0}", filePath), BuildMessageImportance.High); // return the value FullFilePath.Set(context, filePath); }
/// <summary> /// Check in the files that were checked out and edited /// </summary> /// <param name="context"></param> protected override void Execute(CodeActivityContext context) { // Get the workspace passed in as a property var workspace = context.GetValue(Workspace); // Get the list of changes that need to be made. PendingChange[] pendingChanges = workspace.GetPendingChanges(); if ((pendingChanges == null) || (pendingChanges.Length == 0)) { context.WriteBuildMessage("There are no changes pending - No CheckIn will be performed.", BuildMessageImportance.High); } else { context.WriteBuildMessage("Checking in pending changes", BuildMessageImportance.High); // Need to check in the files without initiating a CI build: Passing on "***NO_CI***" as a comment does this // see: http://blogs.msdn.com/b/buckh/archive/2007/07/27/tfs-2008-how-to-check-in-without-triggering-a-build-when-using-continuous-integration.aspx workspace.CheckIn(workspace.GetPendingChanges(), null, "***NO_CI***", null, null, new PolicyOverrideInfo( "Checking in modified AssemblyInfo files as part of Versioning Build Process", null), CheckinOptions.SuppressEvent); } }
/// <summary> /// Does the NuGet Processing work. Formats data into an argument string and then calls NuGet.Exe to do the Push or Push/Publish /// </summary> /// <param name="nuGetExeFilePath">Full path to the nuget.exe application OR empty if nuget is in the machine's path</param> /// <param name="packageLocation">Full path to the NuPkg file that is to be pushed</param> /// <param name="pushDestination">Address of the gallery that nuget.exe will push the package to</param> /// <param name="apiKey">Optional: (if required) the key used to push the package to the nuget gallery</param> /// <param name="context">the workflow/build context - used to send build messages</param> /// <returns>true if the nuget process succeeds</returns> public bool NuGetPublishing(string nuGetExeFilePath, string packageLocation, string pushDestination, string apiKey, CodeActivityContext context) { #region Parameter Validation if (string.IsNullOrWhiteSpace(packageLocation)) { throw new ArgumentNullException("packageLocation"); } if (pushDestination == null) { // Assume that we will push to the NuGet Gallery pushDestination = string.Empty; } #endregion // Match a unc or drive based location - Do a copy if found var regex = new Regex(@"^((\\\\[a-zA-Z0-9-]+\\[a-zA-Z0-9`~!@#$%^&(){}'._-]+([ ]+[a-zA-Z0-9`~!@#$%^&(){}'._-]+)*)|([a-zA-Z]:))(\\[^ \\/:*?""<>|]+([ ]+[^ \\/:*?""<>|]+)*)*\\?$"); if (!regex.Match(pushDestination).Success) { var pushDestinationArgument = string.IsNullOrWhiteSpace(pushDestination) ? string.Empty : string.Format("-s \"{0}\"", pushDestination); var arguments = string.Format("push \"{0}\" {1} {2}", packageLocation, apiKey, pushDestinationArgument); if (context != null) { context.WriteBuildMessage(string.Format("Push Arguments: {0}", arguments), BuildMessageImportance.High); } return(NuGetProcess.RunNuGetProcess(NuGetHelper.ValidateNuGetExe(nuGetExeFilePath), arguments, context)); } var fileName = Path.GetFileName(packageLocation); if (fileName != null) { var destinationFilePath = Path.Combine(pushDestination, fileName); File.Copy(packageLocation, destinationFilePath, true); return(true); } return(false); }
protected override void Execute(CodeActivityContext context) { workspace = context.GetValue(this.Workspace); IBuildDefinition buildDef = context.GetValue(this.BuildDefinition); DateTime? comparison = null; var details = buildDef.QueryBuilds().Where(x => x.Status == BuildStatus.Succeeded).OrderBy(x => x.StartTime); if (details.Count() > 0) { comparison = details.Last().StartTime; } if (!comparison.HasValue) { return; } IEnumerable history = workspace.VersionControlServer.QueryHistory("$/" + context.GetValue(ProjectName), VersionSpec.Latest, 0, RecursionType.Full, null, new DateVersionSpec(comparison.Value), VersionSpec.Latest, Int32.MaxValue, true, false); foreach (Changeset c in history.OfType<Changeset>().OrderBy(x => x.CreationDate)) { foreach (var change in c.Changes.Where(x => x.Item.ItemType == ItemType.File && x.Item.ServerItem.Split('/').Last().ToLower().Contains(".sql") && (x.ChangeType != (ChangeType.Delete | ChangeType.SourceRename | ChangeType.Rename)))) { string fileName = change.Item.ServerItem.Split('/').Last(); WorkingFolder wf = workspace.TryGetWorkingFolderForServerItem(change.Item.ServerItem); if (wf != null && !string.IsNullOrEmpty(wf.LocalItem)) { context.WriteBuildMessage(string.Format("SQL File found: {0}", fileName)); } } } }
protected override void Execute(CodeActivityContext context) { #region Workflow Arguments // This will be the api key or a path to the file with the key in it (or blank) var apiKeyOrFile = ApiKeyOrFile.Get(context); // The local build directory var sourcesDirectory = SourcesDirectory.Get(context); #endregion string resultMessage; var apiKey = ExtractApiKey(apiKeyOrFile, sourcesDirectory, out resultMessage); // Write to the log context.WriteBuildMessage(resultMessage, BuildMessageImportance.High); // Return the value back to the workflow context.SetValue(ApiKeyValue, apiKey); }
/// <summary> /// Does the NuGet Processing work. Formats data into an argument string and then calls NuGet.Exe /// </summary> /// <param name="nuGetExeFilePath">Full path to the nuget.exe application OR empty if nuget is in the machine's path</param> /// <param name="nuSpecFilePath">path to the NuSpec "manifest" file</param> /// <param name="outputDirectory">path to the folder where the generated NuPkg file should be placed</param> /// <param name="basePath">path to the folder containing all of the files that should be packaged</param> /// <param name="versionNumber">optional: is a version number is provided it will be used to override the version of the package</param> /// <param name="additionalOptions">additional NuGet command line arguments (optional)</param> /// <param name="context">the workflow/build context - used to send build messages</param> /// <returns>true if the nuget process succeeds</returns> public bool NuGetPackaging(string nuGetExeFilePath, string nuSpecFilePath, string outputDirectory, string basePath, string versionNumber, string additionalOptions, CodeActivityContext context) { var versionParameter = string.Empty; #region Parameter Validation if (string.IsNullOrWhiteSpace(nuSpecFilePath)) { throw new ArgumentNullException("nuSpecFilePath"); } if (string.IsNullOrWhiteSpace(basePath)) { throw new ArgumentNullException("basePath"); } if (string.IsNullOrWhiteSpace(outputDirectory)) { throw new ArgumentNullException("outputDirectory"); } #endregion // If the version number was provided, then use it if (!string.IsNullOrWhiteSpace(versionNumber)) { versionParameter = string.Format("-version {0}", versionNumber); } var arguments = string.Format( "pack \"{0}\" -OutputDirectory \"{1}\" -BasePath \"{2}\" {3} {4}", nuSpecFilePath, outputDirectory, basePath, versionParameter, additionalOptions).Trim(); if (context != null) { context.WriteBuildMessage(string.Format("CallNuGetPackageCommandLine arguments: {0}", arguments), BuildMessageImportance.High); } return(NuGetProcess.RunNuGetProcess(NuGetHelper.ValidateNuGetExe(nuGetExeFilePath), arguments, context)); }
protected override void Execute(CodeActivityContext context) { #region Extract Workflow Argument Values // The file path of the nuget.exe - if null or empty then // assume nuget is "installed" on the build server and in the path var nuGetExeFilePath = NuGetExeFilePath.Get(context); // The path of the nuspec file var nuSpecFilePath = NuSpecFilePath.Get(context); // The folder location of the files to be packed var basePath = BasePath.Get(context); // The folder location of the files to be packed var outputDirectory = OutputDirectory.Get(context); // The destination location if deployment is to be done var versionNumber = VersionNumber.Get(context); // command line options to append (as is) to the nuget command line var additionalOptions = AdditionalOptions.Get(context); #endregion context.WriteBuildMessage(string.Format("In CallNuGetPackageCommandLine:"), BuildMessageImportance.High); context.WriteBuildMessage(string.Format("nuGetExeFilePath: {0}", nuGetExeFilePath), BuildMessageImportance.High); context.WriteBuildMessage(string.Format("basePath: {0}", basePath), BuildMessageImportance.High); context.WriteBuildMessage(string.Format("outputDirectory: {0}", outputDirectory), BuildMessageImportance.High); context.WriteBuildMessage(string.Format("versionNumber: {0}", versionNumber), BuildMessageImportance.High); context.WriteBuildMessage(string.Format("additionalOptions: {0}", additionalOptions), BuildMessageImportance.High); // Don't assume that DI will have happened. If the value is null then create the default object.);) if (NuGetProcess == null) { NuGetProcess = new NuGetProcess(); } // Call the method that will do the work var results = NuGetPackaging(nuGetExeFilePath, nuSpecFilePath, outputDirectory, basePath, versionNumber, additionalOptions, context); // Send the result back to the workflow NuGetPackagingResult.Set(context, results); }
/// <summary> /// Does the NuGet Processing work. Formats data into an argument string and then calls NuGet.Exe /// </summary> /// <param name="nuGetExeFilePath">Full path to the nuget.exe application OR empty if nuget is in the machine's path</param> /// <param name="nuSpecFilePath">path to the NuSpec "manifest" file</param> /// <param name="outputDirectory">path to the folder where the generated NuPkg file should be placed</param> /// <param name="basePath">path to the folder containing all of the files that should be packaged</param> /// <param name="versionNumber">optional: is a version number is provided it will be used to override the version of the package</param> /// <param name="additionalOptions">additional NuGet command line arguments (optional)</param> /// <param name="context">the workflow/build context - used to send build messages</param> /// <returns>true if the nuget process succeeds</returns> public bool NuGetPackaging(string nuGetExeFilePath, string nuSpecFilePath, string outputDirectory, string basePath, string versionNumber, string additionalOptions, CodeActivityContext context) { var versionParameter = string.Empty; #region Parameter Validation if (string.IsNullOrWhiteSpace(nuSpecFilePath)) { throw new ArgumentNullException("nuSpecFilePath"); } if (string.IsNullOrWhiteSpace(basePath)) { throw new ArgumentNullException("basePath"); } if (string.IsNullOrWhiteSpace(outputDirectory)) { throw new ArgumentNullException("outputDirectory"); } #endregion // If the version number was provided, then use it if (!string.IsNullOrWhiteSpace(versionNumber)) { versionParameter = string.Format("-version {0}", versionNumber); } var arguments = string.Format( "pack \"{0}\" -OutputDirectory \"{1}\" -BasePath \"{2}\" {3} {4}", nuSpecFilePath, outputDirectory, basePath, versionParameter, additionalOptions).Trim(); if (context != null) { context.WriteBuildMessage(string.Format("CallNuGetPackageCommandLine arguments: {0}", arguments), BuildMessageImportance.High); } return NuGetProcess.RunNuGetProcess(NuGetHelper.ValidateNuGetExe(nuGetExeFilePath), arguments, context); }
protected override void Execute(CodeActivityContext context) { #region Workflow Arguments // The TFS source location of the file to get var fileToGet = context.GetValue(FileToGet); // The current workspace - used to create a new workspace for the get var workspace = context.GetValue(Workspace); // The local build directory var buildDirectory = context.GetValue(BuildDirectory); #endregion // Version seed file and path var versionFileDirectory = string.Format("{0}\\VersionSeed", buildDirectory); var filename = Path.GetFileName(fileToGet); var fullPathToSeedFile = Path.Combine(versionFileDirectory, filename); // Return the value back to the workflow context.SetValue(FullPathToSeedFile, fullPathToSeedFile); // Write to the log context.WriteBuildMessage(string.Format("Getting file from Source: {0}", fileToGet), BuildMessageImportance.High); context.WriteBuildMessage(string.Format("Placing version seed file in: {0}", versionFileDirectory), BuildMessageImportance.High); try { // Create workspace and working folder var tempWorkspace = workspace.VersionControlServer.CreateWorkspace("VersionSeed"); var workingFolder = new WorkingFolder(fileToGet, fullPathToSeedFile); // Map the workspace tempWorkspace.CreateMapping(workingFolder); // Get the file var request = new GetRequest(new ItemSpec(fileToGet, RecursionType.None), VersionSpec.Latest); var status = tempWorkspace.Get(request, GetOptions.GetAll | GetOptions.Overwrite); if (!status.NoActionNeeded) { foreach (var failure in status.GetFailures()) { context.WriteBuildMessage( string.Format("Failed to get file from source: {0} - {1}", fileToGet, failure.GetFormattedMessage()), BuildMessageImportance.High); } } // Return the value back to the workflow context.SetValue(FullPathToSeedFile, fullPathToSeedFile); // Get rid of the workspace tempWorkspace.Delete(); } catch (Exception) { context.WriteBuildMessage(string.Format("Seed file exists in '{0}'. Using existing file.", versionFileDirectory), BuildMessageImportance.High); } }