Azure DevOps CI/CD pipeline: Revert commit on failure - azure-devops

I am currently building an Azure DevOps CI/CD pipeline and if it fails, I don't want to keep the code that lead to the fail in my repository. So, if the pipeline fails, I want the repo to be reverted to the last version before that commit. I can't find any help on that. How does this option look like and how can I add this option to my .yaml file?
Thank you so much.

Normally, you can use the git revert command to revert some existing commits.
In your pipeline, you can check out the git repository and the branch where you made the changes. Then run the git revert command to 'undo' some commits.
For more details, you can reference the following articles:
Git - git-revert Documentation
Git Revert
However, as #GeralexGR has suggested, it is recommended that you'd better create a develop branch based on the default branch (main/master) and make changes on this branch. Then build and test the code on the develop branch. Once everything is good on the develop branch, you can create a Pull Request to merge the changes from the develop branch to the default branch.

Related

how to post a github PR that sets the base branch to release_

Developers keep making the mistake on hotfixes to release branches in github. Here are the steps we have right now
git checkout --track origin/release_xxxx (make sure you are on the release branch)
git checkout -b yourName/yourTicketNumber (the hotfix branch)
Modify your code
Post a PR
modify the PR's base branch back to release_xxx
I am wondering if there is a slick way on the last step that once in a while gets missed to automatically use the branch it was branched from instead of main?
Perhaps I just need to create a postHotfix.sh and do the work in there but then people need github tools installed. Any other solutions?
I don't know of an automatic solution, but you can change the base branch when raising your PR in the GitHub UI:
If you're using the GitHub CLI, you can add a -B (or --base) branch as an argument: https://cli.github.com/manual/gh_pr_create

Cherry pick or selective merge from dev branch to prod

I have deployed Azure Data Factory pipelines and associated components to adf_publish branch in Azure Devops. Now I want to deploy those changes to the Prod branch, but the problem is that the Prod branch and adf_publish are not in sync. When I try to create a pull request I get 100 files and 100+ commits will be merged message which is not what I want. I want to merge only 1 Data Factory pipeline which was newly created and associated datasets (8) and Linked Service(1).
I tried the cherry pick method from the adf_publish branch but it still takes everything that is missing from Prod Branch. Is there an easy way to accomplish this either through the Azure Devops UI or through Visual Studio Code.
As per the screenshot below I see + next to multiple pipelines which indicates that they are not present in Prod branch, I just want to merge 1 pipeline and leave all the rest in adf_publish.
Any help would be highly appreciated. I have tried multiple things but nothing is working. Thanks
ADF_Publish branch will generate ARM templates for deployment automatically. Those templates you will be selecting as part of your release pipeline to perform deployment.
So, after merging ARM templates from ADF_Publish branch to another branch, if you are using same ARM template files from another branch to release deployment then it should work.
If the change(s) you seek aren't in separate commits, break the commit into individual commits using the approach outlined here. You use git rebase -i to obtain the original commit to modify, then git reset HEAD to selectively rollback changes, and finally git commit to commit that part as a new commit in the history.
Another useful technique is described in Red Hat Magazine, where they use git add —patch or maybe git add —interactive to add just sections of a hunk if you wish to separate various changes to specific files (search in that page for "split").
After splitting the modifications, you may now pick and choose which ones you wish.

Close a pull request without merging it into the upstream branch in Azure DevOps

Is it possible to close a pull request without merging it into the upstream branch?
I am using gitflow and so I want the developer who started the feature branch to finish the feature branch rather than reviewer to merge the feature branch.
Looks like this facility is available in github.
You can abandon the Pull Request, it will close it without merging:
Ok, So if you want to merge but not delete the feature branch, there is an option. Just uncheck the delete check box.
Now using gitflow, you can now finish the branch. Then git flow will delete the branch locally as well as remotely. And before deleting locally, it will merge changes from the feature branch to the develop locally.

How to use git flow without using release branch?

There are several branches available in git flow.
such as
feature/
release/
support/
hotfix/
bugfix/
I do not need release/ branch and want to merge staging branch (a development branch) directly to master.
What is the best way to achieve this using git flow?
I think this would be mandatory to make release branch for every release in production or your master branch
So There is no alternative way to do this.
Simply flow is as below:
Work on your feature branch
Finish work and merge your feature branch to staging
Make release branch from staging.
Add version and tag than merge it to master amd staging both.
I think this would be helpful for you.

How to config Jenkins to build any branch whenever it committed to GitHub

I'd like to config jenkins that builds any branch whenever it committed to GitHub.
I did as below:
At Source Code Management, I chose Git and Branch Specifier was **
At Build Triggers, I chose Build when a change is pushed to GitHub
I tried to commit to branch (ex: fixBugAAA), but jenkins built all branches.
What did I do wrong? I just need to build only one branch I committed (ex: in this case fixBugAAA). How to do that?
Thanks.