From 6e6128b12c4af649ec1a2ce0134a82a22f5b1e85 Mon Sep 17 00:00:00 2001 From: Alexander Hjelm Date: Fri, 6 Oct 2023 12:24:51 +0200 Subject: [PATCH 1/4] Application returns error code 1 on error --- src/WorkItemMigrator/JiraExport/JiraCommandLine.cs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/WorkItemMigrator/JiraExport/JiraCommandLine.cs b/src/WorkItemMigrator/JiraExport/JiraCommandLine.cs index a48d4a3a..7a90d5c6 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 = false; 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) From e1d96847d88378711ded45adec7c9804be438397 Mon Sep 17 00:00:00 2001 From: Alexander Hjelm Date: Mon, 9 Oct 2023 11:30:53 +0200 Subject: [PATCH 2/4] JiraCommandLine: succeeded is true by default to cover help section execution case --- src/WorkItemMigrator/JiraExport/JiraCommandLine.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/WorkItemMigrator/JiraExport/JiraCommandLine.cs b/src/WorkItemMigrator/JiraExport/JiraCommandLine.cs index 7a90d5c6..60747a53 100644 --- a/src/WorkItemMigrator/JiraExport/JiraCommandLine.cs +++ b/src/WorkItemMigrator/JiraExport/JiraCommandLine.cs @@ -48,7 +48,7 @@ private void ConfigureCommandLineParserWithOptions() commandLineApplication.OnExecute(() => { bool forceFresh = forceOption.HasValue(); - bool succeeded = false; + bool succeeded = true; if (configOption.HasValue()) { From abf4a6545315b6176ec55a4b4fa8e1c80a7fc022 Mon Sep 17 00:00:00 2001 From: Alexander Hjelm Date: Mon, 9 Oct 2023 11:31:21 +0200 Subject: [PATCH 3/4] WiImport: return 0/1 depending on if the execution suceeded or not --- .../WorkItemImport/ImportCommandLine.cs | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/WorkItemMigrator/WorkItemImport/ImportCommandLine.cs b/src/WorkItemMigrator/WorkItemImport/ImportCommandLine.cs index 57ebd6c6..22fa326d 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 { @@ -158,15 +158,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) From 38101b8ff75571c4fb0ec733d9c013f7a367766a Mon Sep 17 00:00:00 2001 From: Alexander Hjelm Date: Mon, 9 Oct 2023 11:46:30 +0200 Subject: [PATCH 4/4] Return code for case: ADO api initialization error --- src/WorkItemMigrator/WorkItemImport/ImportCommandLine.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/WorkItemMigrator/WorkItemImport/ImportCommandLine.cs b/src/WorkItemMigrator/WorkItemImport/ImportCommandLine.cs index 22fa326d..dde796b4 100644 --- a/src/WorkItemMigrator/WorkItemImport/ImportCommandLine.cs +++ b/src/WorkItemMigrator/WorkItemImport/ImportCommandLine.cs @@ -101,7 +101,7 @@ private bool 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);