-
Notifications
You must be signed in to change notification settings - Fork 26
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
base: master
Are you sure you want to change the base?
Conversation
@@ -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}") || { |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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)
function removeRemoteBranches { | ||
cd "${localDirectory}" | ||
|
||
# update list of remotes | ||
git fetch | ||
|
||
# delete mapped remote-branch | ||
git push origin --delete ${sourceBranch} | ||
} |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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 :-)
There was a problem hiding this 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.
# Undo-Level for the script. Used to clean up the resources in case of a failure | ||
undoStage=0 |
There was a problem hiding this comment.
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}") || { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
variableResult=$(az pipelines variable create --pipeline-name "$pipelineName" --value "${artifactPath}") || { | |
az pipelines variable create --pipeline-name "$pipelineName" --value "${artifactPath}" || { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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 :)
if [ -d "./pipelines" ]; then | ||
rm -rf ./pipelines | ||
fi |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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}") || { |
There was a problem hiding this comment.
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 ]
pipelinesDirectoryAlreadyExists=false | ||
|
||
if [ -d "./.pipelines" ]; then | ||
pipelinesDirectoryAlreadyExists=true |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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 ]
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.