public Executable BuildCommandExecutable(string commandPath, string workingDirectory, TimeSpan idleTimeout, ILogger logger) { // Creates an executable pointing to cmd and the working directory being // the repository root var exe = new Executable(commandPath, workingDirectory, idleTimeout); exe.AddDeploymentSettingsAsEnvironmentVariables(_deploymentSettings); UpdateToDefaultIfNotSet(exe, WellKnownEnvironmentVariables.WebRootPath, _environment.WebRootPath, logger); UpdateToDefaultIfNotSet(exe, WellKnownEnvironmentVariables.MSBuildPath, PathUtility.ResolveMSBuildPath(), logger); UpdateToDefaultIfNotSet(exe, WellKnownEnvironmentVariables.KuduSyncCommandKey, KuduSyncCommand, logger); UpdateToDefaultIfNotSet(exe, WellKnownEnvironmentVariables.NuGetExeCommandKey, NuGetExeCommand, logger); UpdateToDefaultIfNotSet(exe, WellKnownEnvironmentVariables.NpmJsPathKey, PathUtility.ResolveNpmJsPath(), logger); exe.SetHomePath(_environment); // Set the path so we can add more variables string path = System.Environment.GetEnvironmentVariable("PATH"); exe.EnvironmentVariables["PATH"] = path; // Add the msbuild path and git path to the %PATH% so more tools are available var toolsPaths = new List<string> { Path.GetDirectoryName(PathUtility.ResolveMSBuildPath()), Path.GetDirectoryName(PathUtility.ResolveGitPath()), Path.GetDirectoryName(PathUtility.ResolveVsTestPath()), Path.GetDirectoryName(PathUtility.ResolveSQLCmdPath()), _environment.ScriptPath }; toolsPaths.AddRange(PathUtility.ResolveNodeNpmPaths()); toolsPaths.Add(PathUtility.ResolveNpmGlobalPrefix()); exe.PrependToPath(toolsPaths); return exe; }
public static void Execute(string workingDirectory, string commandFormat, params object[] args) { var command = String.Format(commandFormat, args); using (new LatencyLogger(NodeExe + " " + command)) { var exe = new Executable(NodeExe, workingDirectory, idleTimeout: TimeSpan.FromSeconds(3600)); exe.SetHomePath(Environment.GetEnvironmentVariable("USERPROFILE")); var result = exe.Execute(command); TestTracer.Trace(" stdout: {0}", result.Item1); TestTracer.Trace(" stderr: {0}", result.Item2); } }
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 Executable BuildCommandExecutable(string commandPath, string workingDirectory, TimeSpan idleTimeout, ILogger logger) { // Creates an executable pointing to cmd and the working directory being // the repository root var exe = new Executable(commandPath, workingDirectory, idleTimeout); exe.AddDeploymentSettingsAsEnvironmentVariables(_deploymentSettings); UpdateToDefaultIfNotSet(exe, WellKnownEnvironmentVariables.WebRootPath, _environment.WebRootPath, logger); UpdateToDefaultIfNotSet(exe, WellKnownEnvironmentVariables.MSBuildPath, PathUtility.ResolveMSBuildPath(), logger); UpdateToDefaultIfNotSet(exe, WellKnownEnvironmentVariables.KuduSyncCommandKey, KuduSyncCommand, logger); UpdateToDefaultIfNotSet(exe, WellKnownEnvironmentVariables.NuGetExeCommandKey, NuGetExeCommand, logger); UpdateToDefaultIfNotSet(exe, WellKnownEnvironmentVariables.NpmJsPathKey, PathUtility.ResolveNpmJsPath(), logger); exe.SetHomePath(_environment); // Set the path so we can add more variables string path = System.Environment.GetEnvironmentVariable("PATH"); exe.EnvironmentVariables["PATH"] = path; // Add the msbuild path and git path to the %PATH% so more tools are available var toolsPaths = new List<string> { Path.GetDirectoryName(PathUtility.ResolveMSBuildPath()), Path.GetDirectoryName(PathUtility.ResolveGitPath()), Path.GetDirectoryName(PathUtility.ResolveVsTestPath()), Path.GetDirectoryName(PathUtility.ResolveSQLCmdPath()), _environment.ScriptPath }; string nodeExePath = PathUtility.ResolveNodePath(); if (!String.IsNullOrEmpty(nodeExePath)) { // If IIS node path is available prepend it to the path list so that it's discovered before any other node versions in the path. toolsPaths.Add(Path.GetDirectoryName(nodeExePath)); } string npmExePath = PathUtility.ResolveNpmCmdPath(); if (!String.IsNullOrEmpty(npmExePath)) { toolsPaths.Add(Path.GetDirectoryName(npmExePath)); } exe.PrependToPath(toolsPaths); return exe; }
private void GenerateScript(DeploymentContext context, ILogger buildLogger) { try { using (context.Tracer.Step("Generating deployment script")) { var scriptGenerator = new Executable(DeploymentScriptGeneratorToolPath, RepositoryPath, DeploymentSettings.GetCommandIdleTimeout()); // Set home path to the user profile so cache directories created by azure-cli are created there scriptGenerator.SetHomePath(System.Environment.GetEnvironmentVariable("APPDATA")); var scriptGeneratorCommand = String.Format(ScriptGeneratorCommandFormat, RepositoryPath, Environment.DeploymentToolsPath, ScriptGeneratorCommandArguments); bool cacheUsed = UseCachedDeploymentScript(scriptGeneratorCommand, context); if (!cacheUsed) { buildLogger.Log(Resources.Log_DeploymentScriptGeneratorCommand, scriptGeneratorCommand); scriptGenerator.ExecuteWithProgressWriter(buildLogger, context.Tracer, scriptGeneratorCommand); CacheDeploymentScript(scriptGeneratorCommand, context); } else { buildLogger.Log(Resources.Log_DeploymentScriptGeneratorUsingCache, scriptGeneratorCommand); } } } 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(); throw; } }
public Executable BuildCommandExecutable(string commandPath, string workingDirectory, TimeSpan idleTimeout, ILogger logger) { // Creates an executable pointing to cmd and the working directory being // the repository root var exe = new Executable(commandPath, workingDirectory, idleTimeout); exe.AddDeploymentSettingsAsEnvironmentVariables(_deploymentSettings); UpdateToDefaultIfNotSet(exe, WellKnownEnvironmentVariables.WebRootPath, _environment.WebRootPath, logger); UpdateToDefaultIfNotSet(exe, WellKnownEnvironmentVariables.MSBuildPath, PathUtility.ResolveMSBuildPath(), logger); UpdateToDefaultIfNotSet(exe, WellKnownEnvironmentVariables.KuduSyncCommandKey, KuduSyncCommand, logger); UpdateToDefaultIfNotSet(exe, WellKnownEnvironmentVariables.NuGetExeCommandKey, NuGetExeCommand, logger); UpdateToDefaultIfNotSet(exe, WellKnownEnvironmentVariables.NpmJsPathKey, PathUtility.ResolveNpmJsPath(), logger); UpdateToDefaultIfNotSet(exe, WellKnownEnvironmentVariables.DnvmPath, DnvmPath, logger); UpdateToDefaultIfNotSet(exe, WellKnownEnvironmentVariables.GypMsvsVersion, Constants.VCVersion, logger); UpdateToDefaultIfNotSet(exe, WellKnownEnvironmentVariables.VCTargetsPath, PathUtility.ResolveVCTargetsPath(), logger); UpdateToDefaultIfNotSet(exe, WellKnownEnvironmentVariables.VCInstallDir140, PathUtility.ResolveVCInstallDirPath(), logger); exe.SetHomePath(_environment); // Set the path so we can add more variables string path = System.Environment.GetEnvironmentVariable("PATH"); exe.EnvironmentVariables["PATH"] = path; 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 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.NuGetExeCommandKey, NuGetExeCommand, logger); UpdateToDefaultIfNotSet(exe, WellKnownEnvironmentVariables.PostDeploymentActionsCommandKey, PostDeploymentActionsCommand, logger); UpdateToDefaultIfNotSet(exe, WellKnownEnvironmentVariables.PostDeploymentActionsDirectoryKey, PostDeploymentActionsDir, logger); UpdateToDefaultIfNotSet(exe, WellKnownEnvironmentVariables.SelectNodeVersionCommandKey, SelectNodeVersionCommand, logger); UpdateToDefaultIfNotSet(exe, WellKnownEnvironmentVariables.NpmJsPathKey, PathUtility.ResolveNpmJsPath(), logger); bool isInPlace = false; string project = _deploymentSettings.GetValue(SettingsKeys.Project); if (!String.IsNullOrEmpty(project)) { isInPlace = PathUtility.PathsEquals(Path.Combine(sourcePath, project), targetPath); } else { isInPlace = PathUtility.PathsEquals(sourcePath, targetPath); } if (isInPlace) { UpdateToDefaultIfNotSet(exe, WellKnownEnvironmentVariables.InPlaceDeployment, "1", logger); } // 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 string path = System.Environment.GetEnvironmentVariable("PATH"); exe.EnvironmentVariables["PATH"] = path; // Add the msbuild path and git path to the %PATH% so more tools are available var toolsPaths = new List<string> { Path.GetDirectoryName(PathUtility.ResolveMSBuildPath()), Path.GetDirectoryName(PathUtility.ResolveGitPath()), Path.GetDirectoryName(PathUtility.ResolveVsTestPath()) }; string nodeExePath = PathUtility.ResolveNodePath(); if (!String.IsNullOrEmpty(nodeExePath)) { // If IIS node path is available prepend it to the path list so that it's discovered before any other node versions in the path. toolsPaths.Add(Path.GetDirectoryName(nodeExePath)); } exe.PrependToPath(toolsPaths); return exe; }
private void GenerateScript(DeploymentContext context, ILogger buildLogger) { try { using (context.Tracer.Step("Generating deployment script")) { var scriptGenerator = new Executable(DeploymentScriptGeneratorToolPath, RepositoryPath, DeploymentSettings.GetCommandIdleTimeout()); scriptGenerator.SetHomePath(HomePath); var scriptGeneratorCommand = String.Format(ScriptGeneratorCommandFormat, RepositoryPath, ScriptGeneratorCommandArguments); buildLogger.Log(Resources.Log_DeploymentScriptGeneratorCommand, scriptGeneratorCommand); scriptGenerator.ExecuteWithProgressWriter(buildLogger, context.Tracer, _ => false, scriptGeneratorCommand); } } 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 buildLogger.Log(ex.Output, LogEntryType.Error); buildLogger.Log(ex.Error, LogEntryType.Error); throw; } }