I have a pipeline that runs every time the main branch gets updated (runs Sonarqube and creates a tag)
I need to get the differences from the previous main status and the new one. Most of our updates to the main branch comes from a merge request with the no fast forward option so normally just doing a git diff HEAD HEAD~1 should do the trick but I was wondering if there is anyway to get that previous state, for example, we perform a no fast forward merge or we manually push more than one merge
I checked the predefined variables without luck https://learn.microsoft.com/en-us/azure/devops/pipelines/build/variables?view=azure-devops&tabs=yaml
Thanks!
Related
My question is a continuation to this post:
Close work items automatically on Release to specific environment
This accepted answer will work perfectly, but only if I can make sure that a build shows just the delta since last build as associated WorkItems, instead of all work items from history. Sometimes I see all items in history as associated work items in a build.
Builds are happening for several environments (Dev, QA, UAT, Prod). How do I make sure that when I run a new build, it only has delta since the last build in that same environment so that I am only looking at new changes that are coming in with a new build?
Update:
I think I get what you mean. Please see if my understanding is accurate: your master branch has many PRs and links to many workitems. You create release1 from the master, and then when the branch is run based on release1 for the first time, the API lists the associated workitems of all the commits of the master. The second time, the incremental workitem compared to the first time can be displayed normally. Later, you created release2 from the master. When the branch was run based on release2 for the first time, the API listed the associated workitems of all commits of the master(This is not you want.). The second time, the incremental workitem compared to the first time can be displayed normally. . What you want is to display incremental workitems from the last run of the branch based on release1 the first time the branch is run based on release2?
If so, it's obviously not possible to use this API to achieve the requirements. As I said in the answer, this API fetch increment refers to the increment based on the same branch, it does not apply to different branches.
But you still have a way to get the "increment" you want, check out this API:
https://learn.microsoft.com/en-us/rest/api/azure/devops/build/builds/get-work-items-between-builds?view=azure-devops-rest-6.0
You just need to compare.
Original Answer:
but only if I can make sure that a build shows just the delta since
last build as associated WorkItems, instead of all work items from
history. Sometimes I see all items in history as associated work items
in a build.
Why do you say 'make sure'?
The API should only get the delta workitems(under the same branch).
I think changes should not contain all of the work items linked to all of the previous commits(since it is only 'changes').
Do you mean the behavior on your side is unstable, do you mean sometimes contains delta changes but sometimes contains all of the changes during the branch lifecycle?
If not, then the understood of yours maybe a little false.
If yes, I think you need to report this issue to the Developer Community. Please also provide your problematic build url there in this situation. StackOverflow is an open forum, so it's not suitable for handling stuff with private information.
Builds are happening for several environments (Dev, QA, UAT, Prod).
How do I make sure that when I run a new build, it only has delta
since the last build in that same environment so that I am only
looking at new changes that are coming in with a new build?
I suggest you put each environment in a different branch, then when you run pipeline based on the related branch, the pipeline should only get the delta changes of current branch and the API should only get the delta workitem commits since the last pipeline run of current branch.
I would like to know the best way to undo a pull request made to the main branch on my GitHub repository.
Context: I don't have a staging server and did everything I could to test some new changes locally, but I missed a few things and want to roll back the merge to add to it before deploying again.
I tried "revert" and I believe this has successfully reverted the changes. I then made a handful of additions and then created a new pull request however GitHub is suggesting the only differences between main and the dev-branch are the latest handful of additions: it does not include all the prior differences between main and the dev-branch.
EDIT (additional context in response to comment): To summarise the overall sequence... I finished work on a branch, created a PR, then merged it to main. When testing on the remote server (production as I don't have another) I realised there was further work required. I wanted to rollback to prior to the merge and used "revert" in GitHub on the web. This does seem to have reverted the changes, but I expected that if I resumed work on the branch (which I hadn't deleted) and then did a subsequent PR when complete, that ALL changes would be included (ie the new changes PLUS the previous differences between the branch and main). This isn't the case... seeimgly only new changes are shown in the diff.
My goal for Jenkins is to trigger a build from a github branch automatically, build the application, make a update to the source and then push the source update to the same branch.
All is working except I find myself in a loop. I'm using the build trigger "Build when a change is pushed to GitHub".
When I push the update to the same branch from within the job, it then triggers the build again putting the whole process into a loop.
What I'm looking to do is somehow put this trigger on hold until the whole job is complete.
(I happen to be building an xcode project and updating the build version number in the plist... not sure that is directly relevant to the problem at hand)
When I push the update to the same branch from within the job, it then triggers the build again putting the whole process into a loop.
Then it would be best to push to a different branch, considering that, even if the GitHub webhook fires again, at least it will fire a JSON payload, with, for the push event, with a different branch name
ref string The full Git ref that was pushed. Example: “refs/heads/master”
By checking the name of the branch push in that payload, you will be able to avoid the loop.
I found myself in the same conondrum, and found the answer:
https://liviutudor.com/2015/12/09/jenkins-ci-trick-to-prevent-task-from-triggering-itself-on-scm-commit/#sthash.j7YTr3l0.dpbs
Basically you can choose the option "Polling ignores commits from specific users", and add your bot's username =]
Simple & elegant
I have a Jenkins build taking branch name as a parameter. Now the problem comes: if I run the build first against branch A, then on a different branch B, and finally come back to branch A, the code change set (revision) on branch A cannot be captured by Jenkins as there is build on B standing in the middle. Does anyone know how to keep change set still visible in this scenario?
The best way to set up builds against multiple branches is to have a separate job for each branch. Since each job points to the specific branch, it will be able to detect the changes made to that branch.
If you have a lot of branches, this can get hard to maintain as job configuration changes will need to be made multiple times. The configuration slicing plugin and the job DSL plugin can help you with this.
I'm trying to identify the proper way of working with multiple branches on Gerrit that would match our workflow.
The way we work with branches right now is: we have master & feature branch. Master is the branch we want to polish and make it ready for release, while feature is obviously a field of intensive work. Now, in our particular case whenever somebody works on a bug fix, they:
create a change targeted for master branch
cherry pick it to the feature branch targeted change
once gerrit code review completes, submit both changes.
now the way i understand cherry-pick, it selects individual commit and merges it to the current change. if that is the case, i would expect to have no merge conflicts in the end, and indeed this workflow works perfectly with just GIT. Gerrit, however, most likely due to its nature (branches are not merged remotely the way these are locally and get a different sha tag) lists a tremendous number of conflicting files in the end.
Now, I resolved all these issues by applying merge strategy (ours on feature, theirs on master), but it does not feel right: if anything was not propagated, it just got discarded.
My question is: is there a safe workflow, similar to the above one, that would in the end produce a clean merge with gerrit?
I would say that it's better, in this case, to merge than to cherry pick.
A cherry pick adds the same changes but not the same commit. So while the source is the same on a cherry pick and merge the git tree is different. When the tree is different and you later do a merge git will think that the commit you previously cherry picked is missing and try to merge that change as well, even if the actual code is already there. That's probably why you get a lot of conflicts.
I would propose another way of working.
When you do normal work you develop on feature and push to Gerrit as normal.
When you do a patch (ie bug fix) on the stable production environment you do that directly on master (or local branches if you like but not on feature)
When the patch as been approved in Gerrit it get's merged into the real master and you can make a pull request to get that change to your local copy. Your version of master is now the same as Gerrits master
Now you would merge all new changes on master into feature. Make sure you do a rebase so that the patch ends up before anything you've already done on feature
Once it's time to deploy all new features you can merge feature into master, push to Gerrit (if you have permissions you can by pass gerrit by pushing directly to master instead of refs/for/master as these changes are already reviewed)
Once all changes are on Gerrits master you do a pull on your master and a merge into feature with rebase making feature a clean branch to work on. It's of course totally valid to have a new feature each release. Both work fine.
I'm a little confused, as this flow should work just fine. If other users submit changes before your bug fix is reviewed/verified/submitted, that could result in merge conflicts, but that should be rare.
If you:
Fix a bug on master
Push to review (creating change A in gerrit)
cherry-pick change A on top of the feature branch (resolving any conflicts from master to feature)
Push the cherry-picked change to review (creating change B)
Review/verify/submit changes A & B
Everything will work fine. The only way for merge conflicts to occur is if other users upload and submit changes between steps 1 and 5. Are you seeing different behavior? Can you provide more details?