From e2477ef65e6728d5c0921ab9fcdad100464ee52e Mon Sep 17 00:00:00 2001 From: BenjaminE Date: Wed, 18 May 2022 17:31:07 +0200 Subject: [PATCH 01/15] first draft --- .../azure-devops/pipeline_generator.sh | 48 ++++++++++++++++++- 1 file changed, 47 insertions(+), 1 deletion(-) diff --git a/scripts/pipelines/azure-devops/pipeline_generator.sh b/scripts/pipelines/azure-devops/pipeline_generator.sh index 3edeb985f..d926f6ef6 100644 --- a/scripts/pipelines/azure-devops/pipeline_generator.sh +++ b/scripts/pipelines/azure-devops/pipeline_generator.sh @@ -43,6 +43,9 @@ red='\e[0;31m' # Common var commonTemplatesPath="scripts/pipelines/azure-devops/templates/common" +# Undo-Level for the script. Used to clean up the resources in case of a failure +undoLevel=0 + function help { echo "" echo "Generates a pipeline on Azure DevOps based on the given definition." @@ -157,6 +160,9 @@ function createNewBranch { [ $? != "0" ] && echo -e "${red}The local directory: '${localDirectory}' cannot be found, please check the path." && exit 1 git checkout -b ${sourceBranch} + + # clear local-branches + ${undoLevel}=1 } function copyYAMLFile { @@ -201,6 +207,9 @@ function commitCommonFiles { git commit -m "Adding the source YAML" git push -u origin ${sourceBranch} + + # clean up remote-branches + ${undoLevel}=2 } function createPipeline { @@ -208,7 +217,9 @@ function createPipeline { echo -ne ${white} # Create Azure Pipeline - az pipelines create --name $pipelineName --yml-path "${pipelinePath}/${yamlFile}" --skip-first-run true + result=$(az pipelines create --name $pipelineName --yml-path "${pipelinePath}/${yamlFile}" --skip-first-run true) + + ${undoLevel}=3 } # Function that adds the variables to be used in the pipeline. @@ -272,6 +283,41 @@ function createPR { fi } +function clearLocalBranches { + cd "${localDirectory}" + + git checkout master + + git branch -D ${sourceBranch} +} + +function clearRemoteBranches { + git push origin ${sourceBranch} +} + +function clearRemotePipeline { + # +} + +function clearPipeline { + +} + +function clearPollution { + # automatically frees all resources + if (${undoLevel} > 0) { + clearLocalBranches() + } + + if (${undoLevel} > 1) { + clearRemoteBranches() + } + + if (${undoLevel} > 2) { + clearRemotePipeline() + } +} + if [[ "$help" == "true" ]]; then help; fi importConfigFile From a5c193c4f2a380b4ea9e010f94c76031d851d6ec Mon Sep 17 00:00:00 2001 From: BenjaminE Date: Wed, 18 May 2022 18:35:11 +0200 Subject: [PATCH 02/15] Update pipeline_generator.sh --- .../azure-devops/pipeline_generator.sh | 73 ++++++++++++------- 1 file changed, 47 insertions(+), 26 deletions(-) diff --git a/scripts/pipelines/azure-devops/pipeline_generator.sh b/scripts/pipelines/azure-devops/pipeline_generator.sh index d926f6ef6..1692d0be4 100644 --- a/scripts/pipelines/azure-devops/pipeline_generator.sh +++ b/scripts/pipelines/azure-devops/pipeline_generator.sh @@ -157,12 +157,16 @@ function createNewBranch { # Create the new branch. cd "${localDirectory}" + + # store current branch + originalBranch=$(git branch --show-current) + [ $? != "0" ] && echo -e "${red}The local directory: '${localDirectory}' cannot be found, please check the path." && exit 1 git checkout -b ${sourceBranch} # clear local-branches - ${undoLevel}=1 + undoLevel=1 } function copyYAMLFile { @@ -209,7 +213,7 @@ function commitCommonFiles { git push -u origin ${sourceBranch} # clean up remote-branches - ${undoLevel}=2 + undoLevel=2 } function createPipeline { @@ -217,9 +221,9 @@ function createPipeline { echo -ne ${white} # Create Azure Pipeline - result=$(az pipelines create --name $pipelineName --yml-path "${pipelinePath}/${yamlFile}" --skip-first-run true) + pipelineResult=$(az pipelines create --name $pipelineName --yml-path "${pipelinePath}/${yamlFile}" --skip-first-run true) - ${undoLevel}=3 + undoLevel=3 } # Function that adds the variables to be used in the pipeline. @@ -229,7 +233,7 @@ function addCommonPipelineVariables { echo "Skipping creation of the variable artifactPath as the flag has not been used." else # Add the extra artifact to store variable. - az pipelines variable create --name "artifactPath" --pipeline-name "$pipelineName" --value "${artifactPath}" + variableResult=$(az pipelines variable create --name "artifactPath" --pipeline-name "$pipelineName" --value "${artifactPath}") fi } @@ -286,36 +290,51 @@ function createPR { function clearLocalBranches { cd "${localDirectory}" - git checkout master + git checkout $originalBranch git branch -D ${sourceBranch} } function clearRemoteBranches { - git push origin ${sourceBranch} -} + # update list of remotes + git fetch -function clearRemotePipeline { - # + # delete mapped remote-branch + git push origin --delete ${sourceBranch} } -function clearPipeline { - +function clearPipelineFiles { + # clear the files + cd "${localDirectory}" + + if [ -d "./pipelines" ]; then + rm -rf ./pipelines + fi } +# function clearPipeline { + +# } + + function clearPollution { # automatically frees all resources - if (${undoLevel} > 0) { - clearLocalBranches() - } - if (${undoLevel} > 1) { - clearRemoteBranches() - } + #if (${undoLevel} > 3) { + # clearVariables + #} - if (${undoLevel} > 2) { - clearRemotePipeline() - } + #if (${undoLevel} > 2) { + # clearPipeline + #} + + if [ ${undoLevel} > 1 ]; then + clearRemoteBranches + fi + + if [ ${undoLevel} > 0 ]; then + clearLocalBranches + fi } if [[ "$help" == "true" ]]; then help; fi @@ -336,12 +355,14 @@ type copyScript &> /dev/null && copyScript commitCommonFiles -type commitFiles &> /dev/null && commitFiles +# type commitFiles &> /dev/null && commitFiles + +# createPipeline -createPipeline +# type addPipelineVariables &> /dev/null && addPipelineVariables -type addPipelineVariables &> /dev/null && addPipelineVariables +# addCommonPipelineVariables -addCommonPipelineVariables +# createPR -createPR +clearPollution From bea78173704c13dcd4063c8a6d99736d585bf57f Mon Sep 17 00:00:00 2001 From: BenjaminE Date: Wed, 18 May 2022 19:23:42 +0200 Subject: [PATCH 03/15] checking for errors and syntax cleanup --- .../azure-devops/pipeline_generator.sh | 41 +++++++++++++------ 1 file changed, 29 insertions(+), 12 deletions(-) diff --git a/scripts/pipelines/azure-devops/pipeline_generator.sh b/scripts/pipelines/azure-devops/pipeline_generator.sh index 1692d0be4..359efc1fe 100644 --- a/scripts/pipelines/azure-devops/pipeline_generator.sh +++ b/scripts/pipelines/azure-devops/pipeline_generator.sh @@ -221,8 +221,19 @@ function createPipeline { echo -ne ${white} # Create Azure Pipeline - pipelineResult=$(az pipelines create --name $pipelineName --yml-path "${pipelinePath}/${yamlFile}" --skip-first-run true) + + pipelineResult=$(az pipelines create --name $pipelineName --yml-path "${pipelinePath}/${yamlFile}" --skip-first-run true) || { + # if the script fails, clean pollution + echo "There was an error creating the pipeline! Please check if you specified the name and got all settings right!" + clearPollution + + exit 127 + } + + pipelineId=$(echo "$pipelineResult" | python -c "import sys, json; print(json.load(sys.stdin)['id'])") + + # pipeline got created successfully undoLevel=3 } @@ -233,7 +244,15 @@ function addCommonPipelineVariables { echo "Skipping creation of the variable artifactPath as the flag has not been used." else # Add the extra artifact to store variable. - variableResult=$(az pipelines variable create --name "artifactPath" --pipeline-name "$pipelineName" --value "${artifactPath}") + variableResult=$(az pipelines variable create --name "artifactPath" --pipeline-name "$pipelineName" --value "${artifactPath}") || { + # if the variable-creation fails, clean up + + echo "There was an error creating the pipeline-artifact-path variable!. Exiting" + + clearPollution + + exit 127 + } fi } @@ -324,9 +343,9 @@ function clearPollution { # clearVariables #} - #if (${undoLevel} > 2) { - # clearPipeline - #} + if [ ${undoLevel} > 2 ]; then + clearPipeline + fi if [ ${undoLevel} > 1 ]; then clearRemoteBranches @@ -355,14 +374,12 @@ type copyScript &> /dev/null && copyScript commitCommonFiles -# type commitFiles &> /dev/null && commitFiles - -# createPipeline +type commitFiles &> /dev/null && commitFiles -# type addPipelineVariables &> /dev/null && addPipelineVariables +createPipeline -# addCommonPipelineVariables +type addPipelineVariables &> /dev/null && addPipelineVariables -# createPR +addCommonPipelineVariables -clearPollution +createPR From 12069359bbbf83ada9ef46703c1c6dcc6b8ccfcc Mon Sep 17 00:00:00 2001 From: BenjaminE Date: Thu, 19 May 2022 08:06:45 +0200 Subject: [PATCH 04/15] fixed a bug in the undoStage-Comparison --- .../azure-devops/pipeline_generator.sh | 49 ++++++++++--------- 1 file changed, 27 insertions(+), 22 deletions(-) diff --git a/scripts/pipelines/azure-devops/pipeline_generator.sh b/scripts/pipelines/azure-devops/pipeline_generator.sh index 359efc1fe..5adb39630 100644 --- a/scripts/pipelines/azure-devops/pipeline_generator.sh +++ b/scripts/pipelines/azure-devops/pipeline_generator.sh @@ -44,7 +44,7 @@ red='\e[0;31m' commonTemplatesPath="scripts/pipelines/azure-devops/templates/common" # Undo-Level for the script. Used to clean up the resources in case of a failure -undoLevel=0 +undoStage=0 function help { echo "" @@ -166,7 +166,7 @@ function createNewBranch { git checkout -b ${sourceBranch} # clear local-branches - undoLevel=1 + undoStage=1 } function copyYAMLFile { @@ -213,7 +213,7 @@ function commitCommonFiles { git push -u origin ${sourceBranch} # clean up remote-branches - undoLevel=2 + undoStage=2 } function createPipeline { @@ -231,10 +231,12 @@ function createPipeline { exit 127 } + echo "Pipelineresult $pipelineResult" + pipelineId=$(echo "$pipelineResult" | python -c "import sys, json; print(json.load(sys.stdin)['id'])") # pipeline got created successfully - undoLevel=3 + undoStage=3 } # Function that adds the variables to be used in the pipeline. @@ -244,7 +246,7 @@ function addCommonPipelineVariables { echo "Skipping creation of the variable artifactPath as the flag has not been used." else # Add the extra artifact to store variable. - variableResult=$(az pipelines variable create --name "artifactPath" --pipeline-name "$pipelineName" --value "${artifactPath}") || { + variableResult=$(az pipelines variable create --pipeline-name "$pipelineName" --value "${artifactPath}") || { # if the variable-creation fails, clean up echo "There was an error creating the pipeline-artifact-path variable!. Exiting" @@ -306,7 +308,7 @@ function createPR { fi } -function clearLocalBranches { +function removeLocalBranches { cd "${localDirectory}" git checkout $originalBranch @@ -314,7 +316,7 @@ function clearLocalBranches { git branch -D ${sourceBranch} } -function clearRemoteBranches { +function removeRemoteBranches { # update list of remotes git fetch @@ -322,7 +324,7 @@ function clearRemoteBranches { git push origin --delete ${sourceBranch} } -function clearPipelineFiles { +function removePipelineFiles { # clear the files cd "${localDirectory}" @@ -331,28 +333,31 @@ function clearPipelineFiles { fi } -# function clearPipeline { - -# } - +function removePipeline { + az pipelines delete --id ${pipelineId} +} function clearPollution { - # automatically frees all resources + # free all resources - #if (${undoLevel} > 3) { - # clearVariables - #} + if [ ${undoStage} -gt 2 ]; then + echo "$undoStage" - if [ ${undoLevel} > 2 ]; then - clearPipeline + echo "Clearing all pipelines!" + + removePipeline fi - if [ ${undoLevel} > 1 ]; then - clearRemoteBranches + if [ ${undoStage} -gt 1 ]; then + echo "Removing all remote branches!" + + removeRemoteBranches fi - if [ ${undoLevel} > 0 ]; then - clearLocalBranches + if [ ${undoStage} -gt 0 ]; then + echo "Removing all local branches!" + + removeLocalBranches fi } From 61df1f42bec1ffabb4d2a16e3e633c694a3d0971 Mon Sep 17 00:00:00 2001 From: BenjaminE Date: Thu, 19 May 2022 08:17:17 +0200 Subject: [PATCH 05/15] comment clean up --- scripts/pipelines/azure-devops/pipeline_generator.sh | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/scripts/pipelines/azure-devops/pipeline_generator.sh b/scripts/pipelines/azure-devops/pipeline_generator.sh index 5adb39630..490322271 100644 --- a/scripts/pipelines/azure-devops/pipeline_generator.sh +++ b/scripts/pipelines/azure-devops/pipeline_generator.sh @@ -155,14 +155,14 @@ function createNewBranch { echo -e "${green}Creating the new branch: ${sourceBranch}..." echo -ne ${white} - # Create the new branch. cd "${localDirectory}" - # store current branch + # store current branch into a variable (only used for rollback/undo) originalBranch=$(git branch --show-current) [ $? != "0" ] && echo -e "${red}The local directory: '${localDirectory}' cannot be found, please check the path." && exit 1 + # Create the new branch. git checkout -b ${sourceBranch} # clear local-branches @@ -309,6 +309,7 @@ function createPR { } function removeLocalBranches { + # visit the directory and switch to the branch which was present before cd "${localDirectory}" git checkout $originalBranch @@ -325,7 +326,7 @@ function removeRemoteBranches { } function removePipelineFiles { - # clear the files + # clear the generated pipeline-files cd "${localDirectory}" if [ -d "./pipelines" ]; then @@ -343,7 +344,7 @@ function clearPollution { if [ ${undoStage} -gt 2 ]; then echo "$undoStage" - echo "Clearing all pipelines!" + echo "Removing all pipelines!" removePipeline fi From 85731af29e41420e0ee72087be0c3fa344d23d92 Mon Sep 17 00:00:00 2001 From: BenjaminE Date: Wed, 25 May 2022 09:03:42 +0200 Subject: [PATCH 06/15] Update pipeline_generator.sh --- .../pipelines/azure-devops/pipeline_generator.sh | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/scripts/pipelines/azure-devops/pipeline_generator.sh b/scripts/pipelines/azure-devops/pipeline_generator.sh index 490322271..be5f0b692 100644 --- a/scripts/pipelines/azure-devops/pipeline_generator.sh +++ b/scripts/pipelines/azure-devops/pipeline_generator.sh @@ -230,9 +230,7 @@ function createPipeline { exit 127 } - - echo "Pipelineresult $pipelineResult" - + pipelineId=$(echo "$pipelineResult" | python -c "import sys, json; print(json.load(sys.stdin)['id'])") # pipeline got created successfully @@ -318,6 +316,8 @@ function removeLocalBranches { } function removeRemoteBranches { + cd "${localDirectory}" + # update list of remotes git fetch @@ -342,15 +342,15 @@ function clearPollution { # free all resources if [ ${undoStage} -gt 2 ]; then - echo "$undoStage" - - echo "Removing all pipelines!" + echo "Removing pipeline with id: ${pipelineId}" removePipeline fi if [ ${undoStage} -gt 1 ]; then - echo "Removing all remote branches!" + echo "Removing all pipeline-files and remote branches!" + + removePipelineFiles removeRemoteBranches fi From 1562b7a19c8f4b7014857bc40fcc627ad65003aa Mon Sep 17 00:00:00 2001 From: BenjaminE Date: Wed, 1 Jun 2022 18:49:40 +0200 Subject: [PATCH 07/15] rename pipeline and abandon pull request --- .../pipelines/azure-devops/pipeline_generator.sh | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/scripts/pipelines/azure-devops/pipeline_generator.sh b/scripts/pipelines/azure-devops/pipeline_generator.sh index be5f0b692..a1d9909f0 100644 --- a/scripts/pipelines/azure-devops/pipeline_generator.sh +++ b/scripts/pipelines/azure-devops/pipeline_generator.sh @@ -165,7 +165,7 @@ function createNewBranch { # Create the new branch. git checkout -b ${sourceBranch} - # clear local-branches + # set undo-stage (clear local branches) undoStage=1 } @@ -226,7 +226,7 @@ function createPipeline { # if the script fails, clean pollution echo "There was an error creating the pipeline! Please check if you specified the name and got all settings right!" - clearPollution + undoPreviousSteps exit 127 } @@ -249,7 +249,7 @@ function addCommonPipelineVariables { echo "There was an error creating the pipeline-artifact-path variable!. Exiting" - clearPollution + undoPreviousSteps exit 127 } @@ -338,7 +338,11 @@ function removePipeline { az pipelines delete --id ${pipelineId} } -function clearPollution { +function abandonPullRequest { + az repos pr update --id id --status abandoned +} + +function undoPreviousSteps { # free all resources if [ ${undoStage} -gt 2 ]; then @@ -351,7 +355,7 @@ function clearPollution { echo "Removing all pipeline-files and remote branches!" removePipelineFiles - + removePullRequest removeRemoteBranches fi From 71822449b0b8cbe40472efef0c75cac4bdffa25e Mon Sep 17 00:00:00 2001 From: BenjaminE Date: Fri, 3 Jun 2022 16:39:25 +0200 Subject: [PATCH 08/15] case sensitiv file removal --- .../azure-devops/pipeline_generator.sh | 20 +++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/scripts/pipelines/azure-devops/pipeline_generator.sh b/scripts/pipelines/azure-devops/pipeline_generator.sh index a1d9909f0..4fc31674c 100644 --- a/scripts/pipelines/azure-devops/pipeline_generator.sh +++ b/scripts/pipelines/azure-devops/pipeline_generator.sh @@ -244,7 +244,7 @@ function addCommonPipelineVariables { echo "Skipping creation of the variable artifactPath as the flag has not been used." else # Add the extra artifact to store variable. - variableResult=$(az pipelines variable create --pipeline-name "$pipelineName" --value "${artifactPath}") || { + $(az pipelines variable create --pipeline-name "$pipelineName" --value "${artifactPath}") || { # if the variable-creation fails, clean up echo "There was an error creating the pipeline-artifact-path variable!. Exiting" @@ -330,7 +330,23 @@ function removePipelineFiles { cd "${localDirectory}" if [ -d "./pipelines" ]; then - rm -rf ./pipelines + + case $configFile in + *"build"*) + rm -rf "build"*;; + *"common"*) + rm -rf "common"*;; + *"library-package"*) + rm -rf "library-package"*;; + *"package"*) + rm -rf "package"*;; + *"quality"*) + rm -rf "quality"*;; + *"test"*) + rm -rf "test";; + *) + echo "Can´t remove files matching the string $configFile";; + esac fi } From c94f7180a64d94cbebd7d38aeb0180500ffd2ff3 Mon Sep 17 00:00:00 2001 From: BenjaminE Date: Fri, 3 Jun 2022 17:18:01 +0200 Subject: [PATCH 09/15] added Timos suggestions --- .../azure-devops/pipeline_generator.sh | 26 +++++++++++-------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/scripts/pipelines/azure-devops/pipeline_generator.sh b/scripts/pipelines/azure-devops/pipeline_generator.sh index 4fc31674c..f146038c4 100644 --- a/scripts/pipelines/azure-devops/pipeline_generator.sh +++ b/scripts/pipelines/azure-devops/pipeline_generator.sh @@ -43,9 +43,6 @@ red='\e[0;31m' # Common var commonTemplatesPath="scripts/pipelines/azure-devops/templates/common" -# Undo-Level for the script. Used to clean up the resources in case of a failure -undoStage=0 - function help { echo "" echo "Generates a pipeline on Azure DevOps based on the given definition." @@ -329,7 +326,8 @@ function removePipelineFiles { # clear the generated pipeline-files cd "${localDirectory}" - if [ -d "./pipelines" ]; then + if [ $pipelinesDirectoryAlreadyExists ]; then + cd "./pipelines" case $configFile in *"build"*) @@ -343,10 +341,12 @@ function removePipelineFiles { *"quality"*) rm -rf "quality"*;; *"test"*) - rm -rf "test";; + rm -rf "test"*;; *) echo "Can´t remove files matching the string $configFile";; esac + else + rm -rf "./pipelines" fi } @@ -354,16 +354,11 @@ function removePipeline { az pipelines delete --id ${pipelineId} } -function abandonPullRequest { - az repos pr update --id id --status abandoned -} - function undoPreviousSteps { # free all resources if [ ${undoStage} -gt 2 ]; then echo "Removing pipeline with id: ${pipelineId}" - removePipeline fi @@ -371,7 +366,6 @@ function undoPreviousSteps { echo "Removing all pipeline-files and remote branches!" removePipelineFiles - removePullRequest removeRemoteBranches fi @@ -384,6 +378,16 @@ function undoPreviousSteps { if [[ "$help" == "true" ]]; then help; fi +# check if the .pipeline-directory already existed +pipelinesDirectoryAlreadyExists=false + +if [ -d "./.pipelines" ]; then + pipelinesDirectoryAlreadyExists=true +fi; + +# Undo-Level for the script. Used to clean up the resources in case of a failure +undoStage=0 + importConfigFile checkInstallations From 4a5107f2059ba8853d9aa44ae37c3b901995239b Mon Sep 17 00:00:00 2001 From: BenjaminE Date: Wed, 8 Jun 2022 08:05:14 +0200 Subject: [PATCH 10/15] file removal --- scripts/pipelines/azure-devops/pipeline_generator.sh | 3 +++ 1 file changed, 3 insertions(+) diff --git a/scripts/pipelines/azure-devops/pipeline_generator.sh b/scripts/pipelines/azure-devops/pipeline_generator.sh index f146038c4..b4d6ac015 100644 --- a/scripts/pipelines/azure-devops/pipeline_generator.sh +++ b/scripts/pipelines/azure-devops/pipeline_generator.sh @@ -309,6 +309,7 @@ function removeLocalBranches { git checkout $originalBranch + # delete branch git branch -D ${sourceBranch} } @@ -357,6 +358,8 @@ function removePipeline { function undoPreviousSteps { # free all resources + removePipelineFiles + if [ ${undoStage} -gt 2 ]; then echo "Removing pipeline with id: ${pipelineId}" removePipeline From e817cc9b69e3df340c6f3f2be439c798c7354f8f Mon Sep 17 00:00:00 2001 From: BenjaminE Date: Wed, 8 Jun 2022 08:44:13 +0200 Subject: [PATCH 11/15] no need to clean files manually since git will do this --- .../azure-devops/pipeline_generator.sh | 43 ++++--------------- 1 file changed, 8 insertions(+), 35 deletions(-) diff --git a/scripts/pipelines/azure-devops/pipeline_generator.sh b/scripts/pipelines/azure-devops/pipeline_generator.sh index b4d6ac015..5ef3d50d0 100644 --- a/scripts/pipelines/azure-devops/pipeline_generator.sh +++ b/scripts/pipelines/azure-devops/pipeline_generator.sh @@ -323,42 +323,12 @@ function removeRemoteBranches { git push origin --delete ${sourceBranch} } -function removePipelineFiles { - # clear the generated pipeline-files - cd "${localDirectory}" - - if [ $pipelinesDirectoryAlreadyExists ]; then - cd "./pipelines" - - case $configFile in - *"build"*) - rm -rf "build"*;; - *"common"*) - rm -rf "common"*;; - *"library-package"*) - rm -rf "library-package"*;; - *"package"*) - rm -rf "package"*;; - *"quality"*) - rm -rf "quality"*;; - *"test"*) - rm -rf "test"*;; - *) - echo "Can´t remove files matching the string $configFile";; - esac - else - rm -rf "./pipelines" - fi -} - function removePipeline { az pipelines delete --id ${pipelineId} } function undoPreviousSteps { - # free all resources - - removePipelineFiles + # undo all actions taken if [ ${undoStage} -gt 2 ]; then echo "Removing pipeline with id: ${pipelineId}" @@ -366,9 +336,8 @@ function undoPreviousSteps { fi if [ ${undoStage} -gt 1 ]; then - echo "Removing all pipeline-files and remote branches!" + echo "Removing all remote branches!" - removePipelineFiles removeRemoteBranches fi @@ -399,11 +368,15 @@ obtainHangarPath createNewBranch -copyYAMLFile +copyYAMLFile copyCommonScript -type copyScript &> /dev/null && copyScript +type copyScript &> /dev/null && copyScript || { + undoPreviousSteps + + exit 127 +} commitCommonFiles From fa45009c50f1deb31c8b27a9bc6a643e8d1330b9 Mon Sep 17 00:00:00 2001 From: BenjaminE Date: Fri, 24 Jun 2022 13:51:44 +0200 Subject: [PATCH 12/15] unused variable --- scripts/pipelines/azure-devops/pipeline_generator.sh | 7 ------- 1 file changed, 7 deletions(-) diff --git a/scripts/pipelines/azure-devops/pipeline_generator.sh b/scripts/pipelines/azure-devops/pipeline_generator.sh index 5ef3d50d0..b45bbd121 100644 --- a/scripts/pipelines/azure-devops/pipeline_generator.sh +++ b/scripts/pipelines/azure-devops/pipeline_generator.sh @@ -350,13 +350,6 @@ function undoPreviousSteps { if [[ "$help" == "true" ]]; then help; fi -# check if the .pipeline-directory already existed -pipelinesDirectoryAlreadyExists=false - -if [ -d "./.pipelines" ]; then - pipelinesDirectoryAlreadyExists=true -fi; - # Undo-Level for the script. Used to clean up the resources in case of a failure undoStage=0 From e0cdc15ac9af5bee5f64ab09ead62130a085ce4b Mon Sep 17 00:00:00 2001 From: BenjaminE Date: Wed, 6 Jul 2022 15:34:16 +0200 Subject: [PATCH 13/15] Update pipeline_generator.sh --- scripts/pipelines/azure-devops/pipeline_generator.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/scripts/pipelines/azure-devops/pipeline_generator.sh b/scripts/pipelines/azure-devops/pipeline_generator.sh index 6604ba13b..b664704ab 100644 --- a/scripts/pipelines/azure-devops/pipeline_generator.sh +++ b/scripts/pipelines/azure-devops/pipeline_generator.sh @@ -221,6 +221,8 @@ obtainHangarPath createNewBranch +undoStage=1 + copyYAMLFile copyCommonScript From 3ae8b43d5aaf481eb7f17f1f0cef454adf933100 Mon Sep 17 00:00:00 2001 From: BenjaminE Date: Wed, 6 Jul 2022 15:36:52 +0200 Subject: [PATCH 14/15] further workaround the changes --- scripts/pipelines/azure-devops/pipeline_generator.sh | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/scripts/pipelines/azure-devops/pipeline_generator.sh b/scripts/pipelines/azure-devops/pipeline_generator.sh index b664704ab..faa8e20b3 100644 --- a/scripts/pipelines/azure-devops/pipeline_generator.sh +++ b/scripts/pipelines/azure-devops/pipeline_generator.sh @@ -221,6 +221,11 @@ obtainHangarPath createNewBranch +cd "${localDirectory}" + +# store current branch into a variable (only used for rollback/undo) +originalBranch=$(git branch --show-current) + undoStage=1 copyYAMLFile From 0012ee0329f698b2d28286748c9c025624e3c0d0 Mon Sep 17 00:00:00 2001 From: BenjaminE Date: Wed, 6 Jul 2022 16:28:45 +0200 Subject: [PATCH 15/15] Update pipeline_generator.sh --- .../pipelines/azure-devops/pipeline_generator.sh | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/scripts/pipelines/azure-devops/pipeline_generator.sh b/scripts/pipelines/azure-devops/pipeline_generator.sh index faa8e20b3..62b8af3f1 100644 --- a/scripts/pipelines/azure-devops/pipeline_generator.sh +++ b/scripts/pipelines/azure-devops/pipeline_generator.sh @@ -206,6 +206,8 @@ if [[ "$help" == "true" ]]; then help; fi # Undo-Level for the script. Used to clean up the resources in case of a failure undoStage=0 +obtainHangarPath + # Load common functions . "$hangarPath/scripts/pipelines/common/pipeline_generator.lib" @@ -217,18 +219,16 @@ importConfigFile checkInstallations -obtainHangarPath - -createNewBranch - cd "${localDirectory}" # store current branch into a variable (only used for rollback/undo) originalBranch=$(git branch --show-current) +createNewBranch + undoStage=1 -copyYAMLFile +copyYAMLFile copyCommonScript @@ -243,7 +243,11 @@ commitCommonFiles # clean up remote-branches undoStage=2 -type commitFiles &> /dev/null && commitFiles +type commitFiles &> /dev/null && commitFiles || { + undoPreviousSteps + + exit 127 +} createPipeline