public Executable BuildExternalCommandExecutable(string workingDirectory, string deploymentTargetPath, ILogger logger) { string sourcePath = _repositoryPath; string targetPath = deploymentTargetPath; // Creates an executable pointing to cmd and the working directory being // the repository root var exe = new Executable(StarterScriptPath, workingDirectory, _deploymentSettings.GetCommandIdleTimeout()); exe.AddDeploymentSettingsAsEnvironmentVariables(_deploymentSettings); UpdateToDefaultIfNotSet(exe, WellKnownEnvironmentVariables.SourcePath, sourcePath, logger); UpdateToDefaultIfNotSet(exe, WellKnownEnvironmentVariables.TargetPath, targetPath, logger); UpdateToDefaultIfNotSet(exe, WellKnownEnvironmentVariables.WebRootPath, _environment.WebRootPath, logger); UpdateToDefaultIfNotSet(exe, WellKnownEnvironmentVariables.MSBuildPath, PathUtility.ResolveMSBuildPath(), logger); UpdateToDefaultIfNotSet(exe, WellKnownEnvironmentVariables.KuduSyncCommandKey, KuduSyncCommand, logger); UpdateToDefaultIfNotSet(exe, WellKnownEnvironmentVariables.SelectNodeVersionCommandKey, SelectNodeVersionCommand, logger); UpdateToDefaultIfNotSet(exe, WellKnownEnvironmentVariables.NpmJsPathKey, PathUtility.ResolveNpmJsPath(), logger); if (PathUtility.PathsEquals(sourcePath, targetPath)) { UpdateToDefaultIfNotSet(exe, WellKnownEnvironmentVariables.InPlaceDeployment, "1", logger); } // Disable this for now // exe.EnvironmentVariables[NuGetCachePathKey] = Environment.NuGetCachePath; // NuGet.exe 1.8 will require an environment variable to make package restore work exe.EnvironmentVariables[WellKnownEnvironmentVariables.NuGetPackageRestoreKey] = "true"; exe.SetHomePath(_environment.SiteRootPath); // Set the path so we can add more variables exe.EnvironmentVariables["PATH"] = System.Environment.GetEnvironmentVariable("PATH"); // Add the msbuild path and git path to the %PATH% so more tools are available var toolsPaths = new[] { Path.GetDirectoryName(PathUtility.ResolveMSBuildPath()), Path.GetDirectoryName(PathUtility.ResolveGitPath()), Path.GetDirectoryName(PathUtility.ResolveVsTestPath()) }; exe.AddToPath(toolsPaths); return exe; }
public Task Build(DeploymentContext context) { var tcs = new TaskCompletionSource<object>(); ILogger customLogger = context.Logger.Log("Running custom deployment command..."); // Creates an executable pointing to cmd and the working directory being // the repository root var exe = new Executable(StarterScriptPath, _repositoryPath, _settings.GetCommandIdleTimeout()); exe.AddDeploymentSettingsAsEnvironmentVariables(_settings); exe.EnvironmentVariables[ExternalCommandFactory.SourcePath] = _repositoryPath; exe.EnvironmentVariables[ExternalCommandFactory.TargetPath] = context.OutputPath; exe.EnvironmentVariables[ExternalCommandBuilder.PreviousManifestPath] = (context.PreviousManifest != null) ? context.PreviousManifest.ManifestFilePath : String.Empty; exe.EnvironmentVariables[ExternalCommandBuilder.NextManifestPath] = context.ManifestWriter.ManifestFilePath; exe.EnvironmentVariables[ExternalCommandFactory.MSBuildPath] = PathUtility.ResolveMSBuildPath(); exe.EnvironmentVariables[ExternalCommandFactory.KuduSyncCommandKey] = KuduSyncCommand; exe.EnvironmentVariables[ExternalCommandFactory.SelectNodeVersionCommandKey] = SelectNodeVersionCommand; exe.EnvironmentVariables[ExternalCommandFactory.NpmJsPathKey] = PathUtility.ResolveNpmJsPath(); exe.EnvironmentVariables[WellKnownEnvironmentVariables.NuGetPackageRestoreKey] = "true"; exe.SetHomePath(_homePath); // Create a directory for the script output temporary artifacts string buildTempPath = Path.Combine(_tempPath, Guid.NewGuid().ToString()); FileSystemHelpers.EnsureDirectory(buildTempPath); exe.EnvironmentVariables[ExternalCommandBuilder.BuildTempPath] = buildTempPath; // Populate the enviornment with the build propeties foreach (var property in _propertyProvider.GetProperties()) { exe.EnvironmentVariables[property.Key] = property.Value; } // Set the path so we can add more variables exe.EnvironmentVariables["PATH"] = System.Environment.GetEnvironmentVariable("PATH"); // Add the msbuild path and git path to the %PATH% so more tools are available var toolsPaths = new[] { Path.GetDirectoryName(PathUtility.ResolveMSBuildPath()), Path.GetDirectoryName(PathUtility.ResolveGitPath()) }; exe.AddToPath(toolsPaths); try { exe.ExecuteWithProgressWriter(customLogger, context.Tracer, _command, String.Empty); tcs.SetResult(null); } catch (CommandLineException ex) { context.Tracer.TraceError(ex); // HACK: Log an empty error to the global logger (post receive hook console output). // The reason we don't log the real exception is because the 'live output' running // msbuild has already been captured. context.GlobalLogger.LogError(); // Add the output stream and the error stream to the log for better // debugging customLogger.Log(ex.Output, LogEntryType.Error); customLogger.Log(ex.Error, LogEntryType.Error); tcs.SetException(ex); } finally { // Clean the temp folder up FileSystemHelpers.DeleteDirectorySafe(buildTempPath); } return tcs.Task; }
// TODO: add specific support in script for this: //protected string GetMSBuildExtraArguments() //{ //if (_settings == null) return String.Empty; //return _settings.GetValue(SettingsKeys.BuildArgs); //} protected void RunCommand(DeploymentContext context, string command) { ILogger customLogger = context.Logger.Log("Running deployment command..."); customLogger.Log("Command: " + command); // Creates an executable pointing to cmd and the working directory being // the repository root var exe = new Executable("cmd", RepositoryPath); exe.AddDeploymentSettingsAsEnvironmentVariables(DeploymentSettings); exe.EnvironmentVariables[SourcePath] = RepositoryPath; exe.EnvironmentVariables[TargetPath] = context.OutputPath; exe.EnvironmentVariables[MSBuildPath] = PathUtility.ResolveMSBuildPath(); exe.EnvironmentVariables[PreviousManifestPath] = context.PreviousManifestFilePath ?? String.Empty; exe.EnvironmentVariables[NextManifestPath] = context.NextManifestFilePath; exe.EnvironmentVariables["KUDU_SYNC_COMMAND"] = KuduSyncPath; // Disable this for now // exe.EnvironmentVariables[NuGetCachePathKey] = Environment.NuGetCachePath; // NuGet.exe 1.8 will require an environment variable to make package restore work exe.EnvironmentVariables[WellKnownEnvironmentVariables.NuGetPackageRestoreKey] = "true"; exe.SetHomePath(HomePath); // Create a directory for the script output temporary artifacts string buildTempPath = Path.Combine(Environment.TempPath, Guid.NewGuid().ToString()); FileSystemHelpers.EnsureDirectory(buildTempPath); exe.EnvironmentVariables[BuildTempPath] = buildTempPath; // Populate the enviornment with the build propeties foreach (var property in PropertyProvider.GetProperties()) { exe.EnvironmentVariables[property.Key] = property.Value; } // Set the path so we can add more variables exe.EnvironmentVariables["PATH"] = System.Environment.GetEnvironmentVariable("PATH"); // Add the msbuild path and git path to the %PATH% so more tools are available var toolsPaths = new[] { Path.GetDirectoryName(PathUtility.ResolveMSBuildPath()), Path.GetDirectoryName(PathUtility.ResolveGitPath()) }; exe.AddToPath(toolsPaths); try { exe.ExecuteWithProgressWriter(customLogger, context.Tracer, ShouldFilterOutMsBuildWarnings, "/c " + command, String.Empty); } catch (CommandLineException ex) { context.Tracer.TraceError(ex); // HACK: Log an empty error to the global logger (post receive hook console output). // The reason we don't log the real exception is because the 'live output' running // msbuild has already been captured. context.GlobalLogger.LogError(); // Add the output stream and the error stream to the log for better // debugging customLogger.Log(ex.Output, LogEntryType.Error); customLogger.Log(ex.Error, LogEntryType.Error); throw new CommandLineException(ex.Message, ex); } finally { // Clean the temp folder up CleanBuild(context.Tracer, buildTempPath); FileSystemHelpers.DeleteDirectorySafe(buildTempPath); } }
public Executable BuildExternalCommandExecutable(string workingDirectory, string deploymentTargetPath) { // Creates an executable pointing to cmd and the working directory being // the repository root var exe = new Executable(StarterScriptPath, workingDirectory, _deploymentSettings.GetCommandIdleTimeout()); exe.AddDeploymentSettingsAsEnvironmentVariables(_deploymentSettings); exe.EnvironmentVariables[SourcePath] = _repositoryPath; exe.EnvironmentVariables[TargetPath] = deploymentTargetPath; exe.EnvironmentVariables[MSBuildPath] = PathUtility.ResolveMSBuildPath(); exe.EnvironmentVariables[KuduSyncCommandKey] = KuduSyncCommand; exe.EnvironmentVariables[SelectNodeVersionCommandKey] = SelectNodeVersionCommand; exe.EnvironmentVariables[NpmJsPathKey] = PathUtility.ResolveNpmJsPath(); // Disable this for now // exe.EnvironmentVariables[NuGetCachePathKey] = Environment.NuGetCachePath; // NuGet.exe 1.8 will require an environment variable to make package restore work exe.EnvironmentVariables[WellKnownEnvironmentVariables.NuGetPackageRestoreKey] = "true"; exe.SetHomePath(_environment.SiteRootPath); // Set the path so we can add more variables exe.EnvironmentVariables["PATH"] = System.Environment.GetEnvironmentVariable("PATH"); // Add the msbuild path and git path to the %PATH% so more tools are available var toolsPaths = new[] { Path.GetDirectoryName(PathUtility.ResolveMSBuildPath()), Path.GetDirectoryName(PathUtility.ResolveGitPath()) }; exe.AddToPath(toolsPaths); return exe; }
public Task Build(DeploymentContext context) { var tcs = new TaskCompletionSource<object>(); ILogger customLogger = context.Logger.Log("Running custom deployment command..."); // Creates an executable pointing to cmd and the working directory being // the repository root var exe = new Executable("cmd", _repositoryPath); exe.EnvironmentVariables[SourcePath] = _repositoryPath; exe.EnvironmentVariables[TargetPath] = context.OutputPath; // Create a directory for the script output temporary artifacts string buildTempPath = Path.Combine(_tempPath, Guid.NewGuid().ToString()); FileSystemHelpers.EnsureDirectory(buildTempPath); exe.EnvironmentVariables[BuildTempPath] = buildTempPath; // Populate the enviornment with the build propeties foreach (var property in _propertyProvider.GetProperties()) { exe.EnvironmentVariables[property.Key] = property.Value; } // Set the path so we can add more variables exe.EnvironmentVariables["PATH"] = System.Environment.GetEnvironmentVariable("PATH"); // Add the msbuild path and git path to the %PATH% so more tools are available var toolsPaths = new[] { Path.GetDirectoryName(PathUtility.ResolveMSBuildPath()), Path.GetDirectoryName(PathUtility.ResolveGitPath()) }; exe.AddToPath(toolsPaths); try { string output = exe.ExecuteWithConsoleOutput(context.Tracer, "/c " + _command, String.Empty).Item1; customLogger.Log(output); tcs.SetResult(null); } catch (Exception ex) { context.Tracer.TraceError(ex); // HACK: Log an empty error to the global logger (post receive hook console output). // The reason we don't log the real exception is because the 'live output' running // msbuild has already been captured. context.GlobalLogger.LogError(); customLogger.Log(ex); tcs.SetException(ex); } finally { // Clean the temp folder up FileSystemHelpers.DeleteDirectorySafe(buildTempPath); } return tcs.Task; }