diff --git a/src/WorkItemMigrator/JiraExport/JiraCommandLine.cs b/src/WorkItemMigrator/JiraExport/JiraCommandLine.cs index a48d4a3a..60747a53 100644 --- a/src/WorkItemMigrator/JiraExport/JiraCommandLine.cs +++ b/src/WorkItemMigrator/JiraExport/JiraCommandLine.cs @@ -48,25 +48,27 @@ private void ConfigureCommandLineParserWithOptions() commandLineApplication.OnExecute(() => { bool forceFresh = forceOption.HasValue(); + bool succeeded = true; if (configOption.HasValue()) { - ExecuteMigration(userOption, passwordOption, urlOption, configOption, forceFresh, continueOnCriticalOption); + succeeded = ExecuteMigration(userOption, passwordOption, urlOption, configOption, forceFresh, continueOnCriticalOption); } else { commandLineApplication.ShowHelp(); } - return 0; + return succeeded ? 0 : 1; }); } - private void ExecuteMigration(CommandOption user, CommandOption password, CommandOption url, CommandOption configFile, bool forceFresh, CommandOption continueOnCritical) + private bool ExecuteMigration(CommandOption user, CommandOption password, CommandOption url, CommandOption configFile, bool forceFresh, CommandOption continueOnCritical) { var itemsCount = 0; var exportedItemsCount = 0; var sw = new Stopwatch(); + bool succeeded = true; sw.Start(); try @@ -137,15 +139,18 @@ private void ExecuteMigration(CommandOption user, CommandOption password, Comman catch (CommandParsingException e) { Logger.Log(LogLevel.Error, $"Invalid command line option(s): {e}"); + succeeded = false; } catch (Exception e) { Logger.Log(e, $"Unexpected migration error."); + succeeded = false; } finally { EndSession(itemsCount, sw); } + return succeeded; } private static void InitSession(ConfigJson config, string continueOnCritical) diff --git a/src/WorkItemMigrator/WorkItemImport/ImportCommandLine.cs b/src/WorkItemMigrator/WorkItemImport/ImportCommandLine.cs index 49d81c69..14be4298 100644 --- a/src/WorkItemMigrator/WorkItemImport/ImportCommandLine.cs +++ b/src/WorkItemMigrator/WorkItemImport/ImportCommandLine.cs @@ -48,25 +48,24 @@ private void ConfigureCommandLineParserWithOptions() CommandOption forceOption = commandLineApplication.Option("--force", "Forces execution from start (instead of continuing from previous run)", CommandOptionType.NoValue); CommandOption continueOnCriticalOption = commandLineApplication.Option("--continue", "Continue execution upon a critical error", CommandOptionType.SingleValue); - commandLineApplication.OnExecute(() => { bool forceFresh = forceOption.HasValue(); - + bool succeeded = true; if (configOption.HasValue()) { - ExecuteMigration(tokenOption, urlOption, configOption, forceFresh, continueOnCriticalOption); + succeeded = ExecuteMigration(tokenOption, urlOption, configOption, forceFresh, continueOnCriticalOption); } else { commandLineApplication.ShowHelp(); } - return 0; + return succeeded ? 0 : 1; }); } - private void ExecuteMigration(CommandOption token, CommandOption url, CommandOption configFile, bool forceFresh, CommandOption continueOnCritical) + private bool ExecuteMigration(CommandOption token, CommandOption url, CommandOption configFile, bool forceFresh, CommandOption continueOnCritical) { ConfigJson config = null; var itemCount = 0; @@ -74,6 +73,7 @@ private void ExecuteMigration(CommandOption token, CommandOption url, CommandOpt var importedItems = 0; var sw = new Stopwatch(); sw.Start(); + bool succeeded = true; try { @@ -101,7 +101,7 @@ private void ExecuteMigration(CommandOption token, CommandOption url, CommandOpt if (agent == null) { Logger.Log(LogLevel.Critical, "Azure DevOps/TFS initialization error."); - return; + return false; } var executionBuilder = new ExecutionPlanBuilder(context); @@ -169,15 +169,18 @@ private void ExecuteMigration(CommandOption token, CommandOption url, CommandOpt catch (CommandParsingException e) { Logger.Log(LogLevel.Error, $"Invalid command line option(s): {e}"); + succeeded = false; } catch (Exception e) { Logger.Log(e, $"Unexpected migration error."); + succeeded = false; } finally { EndSession(itemCount, revisionCount, sw); } + return succeeded; } private static void BeginSession(string configFile, ConfigJson config, bool force, Agent agent, int itemsCount, int revisionCount)