From ba2a61645d5b9920ae11f484c1a62db546920bed Mon Sep 17 00:00:00 2001 From: Bill Date: Thu, 18 Jun 2020 13:25:03 -0500 Subject: [PATCH] fix: Adding ignore flag to ingredient - If set, failed ingredient will not fail a build (#165) --- Schema.md | 3 +++ core/src/bake-interfaces.ts | 1 + system/src/bake-runner.ts | 27 ++++++++++++++++++++++----- 3 files changed, 26 insertions(+), 5 deletions(-) diff --git a/Schema.md b/Schema.md index 41dfa026..55732aa6 100644 --- a/Schema.md +++ b/Schema.md @@ -80,6 +80,7 @@ An ingredient block describes an instance of an ingredient to deploy. It has a l properties: type: string condition: variable + ignoreErrors: bool source: string tokens: {string: variable} parameters: {string: variable} @@ -90,6 +91,7 @@ dependsOn: [string] |----------|----------|------------| |type|yes|name of ingredient to deploy (check ingredient docs for name)| |condition|no|optional condition check that will skip this ingredient if it returns false| +|ignoreErrors|no|If true, any errors from the ingredient will be logged, but not stop other ingredients from running. Will also not fail the deployment| |source|depends on ingredient|source file/option for some ingredients| |tokens|depends on ingredient|Token values typically used to update configuration files when deployed. Check ingredient docs for token options| |parameters|depends on ingredient|check ingredient docs for parameter options| @@ -115,6 +117,7 @@ recipe: custom-script: properties: type: "@azbake/ingredient-script" + ignoreErrors: true source: ./script.ts parameters: name: "[coreutils.create_storage_name('wpoctest1')]" diff --git a/core/src/bake-interfaces.ts b/core/src/bake-interfaces.ts index b105969c..e97c3ecb 100644 --- a/core/src/bake-interfaces.ts +++ b/core/src/bake-interfaces.ts @@ -27,6 +27,7 @@ export interface IIngredientProperties { type: string, source: BakeVariable, condition?: BakeVariable, + ignoreErrors?: boolean parameters: Map, tokens: Map, alerts: Map diff --git a/system/src/bake-runner.ts b/system/src/bake-runner.ts index 8ac60b04..379222da 100644 --- a/system/src/bake-runner.ts +++ b/system/src/bake-runner.ts @@ -64,8 +64,15 @@ export class BakeRunner { } } catch (e) { - this._logger.error("Error running condition check for " + ingredientName + " => " + e); - foundErrors = true; + const shouldIgnoreErrors: boolean = ingredient.properties.ignoreErrors || false + if (shouldIgnoreErrors) { + this._logger.log(red("Error running condition check for " + ingredientName + " => " + e)); + this._logger.log("ignoring above error and continuing") + } else { + this._logger.error("Error running condition check for " + ingredientName + " => " + e); + foundErrors = true + } + finished.push(ingredientName) continue } @@ -75,9 +82,19 @@ export class BakeRunner { if (exec) { let promise = exec.Execute().then(() => { return ingredientName }).catch((err) => { - this._logger.error(err) - foundErrors = true - return ingredientName + + const shouldIgnoreErrors: boolean = ingredient.properties.ignoreErrors || false + + if (shouldIgnoreErrors) { + this._logger.log(red(err)) + this._logger.log("ignoring above error and continuing") + } + else { + this._logger.error(err) + foundErrors = true + } + + return ingredientName }) executing.push(promise)