I'm using Blue Ocean against Bitbucket Server. I want a new build to occur:
When a Pull Request is created or updated
When master is updated (basically, when a PR is merged to master)
It appears that I can do the first by choosing "Discover Branches: Only branches that are also filed as PR's". I can do the second by choosing "Filter by name: master".
But if I specify both, it seems to apply the name filter to discovered branches, so no PR's are ever discovered. Furthermore, it never builds master because master is never the subject of a PR (we have master locked against direct commits, as is common in enterprise development.)
I figured it out but it was not intuitive. You must add two BitBucket Branch Sources, both pointing to the same Repository. The first must be the Filter by Name: Master. The second must be "Discover Branches: Only branches that are also filed as PR's". If they're in the opposite order, they won't work.
Related
In my company we have the following workflow: development is done on a dev branch, once author wants to merge the changes he/she squashes the changes and create a Pull Request. If during the review turns out the rework is needed then the author adds new commits to the branch. Once everything is approved the author should squash commits and rebase the code (if needed). Then the maintainer merges the branch to the master branch, which results in one commit only to be added (plus the merge commit). This is to keep the log neat.
However occasionally the maintainer overlooks the fact the commits on the dev branch weren't squashed which results in multiple "work in progress" commits to be included in the master branch. We want to avoid the situation. The question is how to do that?
I was looking through Pull Request "merge check" plugins that could e.g. disable "Merge" button if there is more than 1 commit between source and destination branches, but so far I haven't found any.
I know we could enable automatic squashing on merge but we decided not to squash automatically. We feel it's better for us if the squash is done manually by the developer, e.g. commit message may be corrected accordingly.
Correcting the history in the master branch is also not possible due to our policy forbidding rewriting history on that branch.
Please read carefully as I believe my use case is unique and I have tried searching a lot on how to do this, but I am still unsure.
Generally, I am trying to set up a repo for a group of developers to work on and have it contain CI checks and require reviewers. However, I have run into some issues with how Github enforces branch protection. On top of that, I cannot use Actions as we are using a self-hosted Enterprise Github through an organization.
My desires:
Use Jenkins (which is already set up and building) builds as checks for PRs. If the checks don't pass, you cannot click merge on the PR.
Allow pushing to a branch that I have a PR up for so the author can push changes based on PR comments.
Require two approvals from maintainers. You cannot click merge without these.
It seems I could protect a master branch for example. However, I would like to enforce the PR checks whenever a person chooses to make a PR. For example, from one dev branch into another dev branch.
Use case:
An author sets up a PR for merging a branch some-work into dev. Jenkins builds the HEAD of the branch some-work to evaluate the checks. I would like to enforce this PR to have two approvals from maintainers. So, those reviewers make some comments and request some changes. The author makes those changes and pushes a new commit to the some-work branch. Jenkins runs on the new HEAD to reevaluate the checks. Then, if-and-only-if the two reviewers approve and the checks pass can the merge button be clicked.
What I have tried:
Using Github branch protections: the required approvals and the required status checks. However, this prevents any pushing or force pushing to the branch being developed on. I could just apply these protections to master, but I also want these checks part of any PR (even dev2->dev1, for example).
Github actions, but these are not available in the self-hosted enterprise Github I have to use.
What I understand:
I understand that I can protect master, for example, in this manner with the native Github branch protection. However, if I want master to be something that always works, it is understandable that developers would break up a feature into multiple branches. They would also want their follow developers to review it when merging it from their branch to an intermediate (non-master) branch. Then the actual branch being merged into master consists of code written by many developers.
Thank you all in advance for your time and help. :)
Using Github branch protections: the required approvals and the required status checks.
However, this prevents any pushing or force pushing to the branch being developed on
But... that issue (not being able to push a protected branch) could be part of a possible solution.
I would make jenkins create/reset a PR branch based on a push on a topic branch (like some-work-pr, based on some-work)
some-work is not protected, and can receive commits at any time
some-work-pr is created by Jenkins protected, and cannot be modified: compilation/test/review/approval happens here.
PR would only be done from xxx-pr branches (protected PR branches created/managed by Jenkins), while other topic branches continue to evolve.
You can only enforce these policies with branch protections, so if you want to enable required CI checks before merging a PR for all branches, then you need to protect all branches (e.g., with the pattern **). In that case, you'll need to have developers use a forking model for your repositories so that they can push code to their forks and then merge in the changes via pull requests only.
Note that if you adopt an approach where projects are implemented as a set of small, incremental changes that are merged frequently and use feature flags to control whether the code is enabled, then as a practical matter developers will only merge into the main branch and you can get away with only protecting the main branch.
We're using Gerrit. We thought we could do the following:
create some commits on a topic branch:
- a
- b
- c
Push those commits to gerrit.
Get some reviews.
Have Jenkins build only the last commit of the bunch.
Unfortunately, it looks like gerrit internally creates three different branches for those three commits, and when we have Jenkins run the script to build the topic, it winds up picking a different commit than the one we intended. Is there someway to get the behavior we desire?
You can change the project configuration to only create one review for your series of changes. This can be done by setting the Create a new change for every commit not in the target branch to false
Biggest disadvantage is that you can't review what has been changed in the changesets leading up to the latest change.
See the Gerrit Documentation
Gerrit always creates one change (review) for each commit pushed. There's no way to create one unique change for a bunch of commits. Commits are stored in special branches (like, for example, refs/changes/12/40312/1) until they aren't submitted (merged in the final branch).
You can, of course, build several commits at once after they are submitted to the branch but you only can trigger Jenkins to start a build every time some commit is merged in the branch (one build for each commit). If you want to have just one build for a bunch of commits you could consider to make scheduled builds started automatically some time of the day (night builds).
I Have been working on bitbucket and jenkins for android applications. I am having many branches in my repository and i want to track just my master branch in jenkins where it meets the following criteria. 1) When we push any code with name 'A' into master it should automatically trigger a build.2) when we push a code as name 'B' into the same master branch it shouldn't trigger the build. Is there a way to do it. I tried excluding branch by using :^(?!.release).*$ but it is picking all other branches too.
Can anyone help?
You can specify which branch to be built in your job like this:
If you don't want the build to occur for specific codes then you can add them in to the Excluded Regions
Go to Additional Behaviors under Git in your job configuration and select Polling ignores commits in certain pathsand add the paths to the files for those you want to ignore builds if any changes happen to them:
This should work!
When using Gerrit Code Review - is it possible to checkout all unreviewed changes for the master branch in one go? I know it is possible to checkout a specific patch set (https://gerrit-documentation.storage.googleapis.com/Documentation/2.12.2/intro-quick.html#_trying_out_the_change), but I would like to get all pending-review commits for the master branch.
Background: we currently aren't using Gerrit yet but we are going to. We have both automated and manual testing of the master branch and I would like to be able to keep on using that, before the review step, so I need to be able to checkout a branch with all pending-review commits.
AFAIK, Gerrit does not provide that feature. In fact, I am not sure if that is even possible without human interaction. If there are N independent unreviewed commits to master, there could be conflicts between them that would make it impossible to automatically build up a branch made of all N commits on top of master.