Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/block96 Undo the changes made in case of pipeline generation failure #108

Open
wants to merge 16 commits into
base: master
Choose a base branch
from

Conversation

BenjaminE98
Copy link
Contributor

@BenjaminE98 BenjaminE98 commented May 25, 2022

This closes #96

If the script fails, we rollback the necessary changes like removing the remote branches. removing the pipeline and local branches.

The idea was to create a variable called undoStage. This sets the stages which need to be undone.

@BenjaminE98 BenjaminE98 changed the title Clear pipeline Feature/block96 Undo the changes made in case of pipeline generation failure May 25, 2022
@@ -218,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.
az pipelines variable create --name "artifactPath" --pipeline-name "$pipelineName" --value "${artifactPath}"
variableResult=$(az pipelines variable create --pipeline-name "$pipelineName" --value "${artifactPath}") || {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SC2034: variableResult appears unused. Verify use (or export if used externally).

(at-me in a reply with help or ignore)


Was this a good recommendation?
[ 🙁 Not relevant ] - [ 😕 Won't fix ] - [ 😑 Not critical, will fix ] - [ 🙂 Critical, will fix ] - [ 😊 Critical, fixing now ]

git checkout -b ${sourceBranch}

# clear local-branches
Copy link
Contributor

@patricpoba patricpoba May 26, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clear local-branches comment may be misleading for another developer.
may be something like set undo stage (clear local-branches)

Comment on lines +318 to +326
function removeRemoteBranches {
cd "${localDirectory}"

# update list of remotes
git fetch

# delete mapped remote-branch
git push origin --delete ${sourceBranch}
}
Copy link
Contributor

@patricpoba patricpoba May 26, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you have to delete the pull request created by the createPR step before removing the remote branch. that means you need another function to undo the createPR step.

az pipelines delete --id ${pipelineId}
}

function clearPollution {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@BenjaminE98
I understand what you mean hear by the name clearPollution but I suggest renaming it to something more self explanatory like undoPreviousSteps or rollbackPreviousActions or something else :-)

Copy link
Contributor

@patricpoba patricpoba left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The work done looks good to me. I left a few comments based on what I have seen so far.

Edit:
Also delete the docker credentials created by the script in AzureDevOps otherwise the subsequent script runs will fails.

Comment on lines 46 to 47
# Undo-Level for the script. Used to clean up the resources in case of a failure
undoStage=0
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This assignment will work but I'd put this one either at the start of the "importConfigFile" function body or I'd put all undoStage assignments at the bottom between where the functions are called. Doesn't matter what you choose but better be consistent, I guess.

@@ -218,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.
az pipelines variable create --name "artifactPath" --pipeline-name "$pipelineName" --value "${artifactPath}"
variableResult=$(az pipelines variable create --pipeline-name "$pipelineName" --value "${artifactPath}") || {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
variableResult=$(az pipelines variable create --pipeline-name "$pipelineName" --value "${artifactPath}") || {
az pipelines variable create --pipeline-name "$pipelineName" --value "${artifactPath}" || {

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or is there a reason for the assignment?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Regarding the variable result - not at all. Regarding the pipeline though I need it because I need to extract the id :) Azures Rest API uses the id of the pipeline to delete it :)

Comment on lines 332 to 334
if [ -d "./pipelines" ]; then
rm -rf ./pipelines
fi
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we need more granularity than just removing it, as this would also undo any previous runs of the pipeline generator. What we want is to only remove it when there were no previous runs. If there were previous runs, we need to keep a copy of the previous state of the .pipeline, alternatively we could also check what type of config file is currently used and granularly delete only the files belonging to that config.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a really good suggestion that I need to apply! Thank you :) I just need to see how

@@ -218,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.
az pipelines variable create --name "artifactPath" --pipeline-name "$pipelineName" --value "${artifactPath}"
$(az pipelines variable create --pipeline-name "$pipelineName" --value "${artifactPath}") || {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SC2091: Remove surrounding $() to avoid executing output (or use eval if intentional).

(at-me in a reply with help or ignore)


Was this a good recommendation?
[ 🙁 Not relevant ] - [ 😕 Won't fix ] - [ 😑 Not critical, will fix ] - [ 🙂 Critical, will fix ] - [ 😊 Critical, fixing now ]

@BenjaminE98 BenjaminE98 marked this pull request as ready for review June 8, 2022 06:45
pipelinesDirectoryAlreadyExists=false

if [ -d "./.pipelines" ]; then
pipelinesDirectoryAlreadyExists=true
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SC2034: pipelinesDirectoryAlreadyExists appears unused. Verify use (or export if used externally).

(at-me in a reply with help or ignore)


Was this a good recommendation?
[ 🙁 Not relevant ] - [ 😕 Won't fix ] - [ 😑 Not critical, will fix ] - [ 🙂 Critical, will fix ] - [ 😊 Critical, fixing now ]

# visit the directory and switch to the branch which was present before
cd "${localDirectory}"

git checkout $originalBranch
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SC2154: originalBranch is referenced but not assigned.

Reply with "@sonatype-lift help" for info about LiftBot commands.
Reply with "@sonatype-lift ignore" to tell LiftBot to leave out the above finding from this PR.
Reply with "@sonatype-lift ignoreall" to tell LiftBot to leave out all the findings from this PR and from the status bar in Github.

When talking to LiftBot, you need to refresh the page to see its response. Click here to get to know more about LiftBot commands.


Was this a good recommendation?
[ 🙁 Not relevant ] - [ 😕 Won't fix ] - [ 😑 Not critical, will fix ] - [ 🙂 Critical, will fix ] - [ 😊 Critical, fixing now ]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Feature: Undo the changes made in case of pipeline generation failure
3 participants