Avoid Gitlab-CI build for develop branch on finish release (git-flow) - continuous-integration

We are using Git-Flow with automatic builds and releases using Gitlab-CI.
Every commit on the develop branch triggers the build stage.
Every commit on the master branch triggers first the build stage and then the release stage (which uses the artifacts from the build stage).
This works fine, there is only one drawback for which I couldn't find a solution:
Whenever we finish a release in the git repository, this means commits on both develop and master branch. That also triggers the build stage on both branches, building from the exact same source versions (at this point there are two different commits that contain the exact same code).
I would like to avoid the build on the development branch, but only in this special case.
I don't think this is possible using the logic inside .gitlab-ci.yml, but that's ok. I would be glad if I could recognize this situation and end the build script early.
I think this means the following conditions have all to be met:
We are on the develop branch. (simple)
The current commit was merged from both master and develop.
The merged master commit has a tag attached to it.
What git magic could I do to recognize if this is the case for a certain commit in the develop branch?
I am using Python for this, but I would appreciate helpful answers in any programming language :-)

maybe you can use only in gitlab-ci.yml
deploy-dev:
stage: deploy-dev
script:
- ./somescript.sh
only:
refs:
- develop
deploy-prod:
stage: deploy-prod
script:
- ./somescript.sh
only:
refs:
- master
- tags

Related

Jenkins pipeline triggered for all branches on code commit in Develop branch

Can anyone help me with any solution for the below issue:
My developer is pushing the code in Dev branch of Bitbucket but in Jenkins, it triggers Dev, Test, Stage and Prod pipeline though there are no changes deployed in Other branches and it simply redeploys the last commit in Test, Stage, and Prod. But then why should any code push to the DEV branch trigger another pipeline.
Please note that every env pipeline is only checking out the respective env branch for deployment. I had raised this issue with the Bitbucket community as well but they confirmed that no issues are seen from Bitbucket's end and suggested to check from Jenkins's end.
In my Jenkins, every pipeline is triggered based on "Build whenever a change is pushed to Bitbucket"
Multi-branch Pipeline should be the way to go here. Makes your file much easier.
Alternative would be to write a script block in your declarative pipelines (or write scripted pipeline directly) which would evaluate the git.branch env variable and only run the job when the branch is correct.
This would work and be somewhat maintainable when you have a fixed set of branches. If you have dev-s creating new branches here and there then this would become overwhelming very fast.

Is there a way to only trigger a build in Teamcity if there were file changes?

We're using teamcity with github enterprise. And we have it set to run on merge requests as well as commits. However, git keeps sending teamcity commit messages for merges that have 0 file changes, which triggers a build.
For example, this will trigger a build:
I've found the documentation here for creating a trigger filter
But I don't see a way to create a filter on the number of updated files.
I think this is what's causing the builds
Triggering a Build on Branch Merge
The VCS trigger is fully aware of branches and will trigger a build once a check-in is detected in a branch.
When changes are merged / fast-forwarded from one branch to another, strictly speaking there are no actual changes in the code. By default, the VCS trigger behaves in the following way:
- When merging/fast forwarding of two non-default branches: the changes
in a build are calculated with regard to previous builds in the same
branch, so if there is a build on same commit in a different branch,
the trigger will start a build in another branch pointing to the same
commit.
- If the default branch is one of the branches in the
merging/fast-forwarding, the changes are always calculated against
the default branch, if there is a build on same revision in the
default branch, TeamCity will not run a new build on the same
revision.
It's worth noting, that builds on branches that haven't been updated will be triggered by a merge in another branch.
You probably use checkout rules. Otherwise, running a build on a merge commit with 0 files seems an appropriate action: the commit does change the content of the checkout directory and should trigger a build.
If you limit what you checkout via TeamCity checkout rules, TeamCity only displays the merge commit with 0 files if it actually changes the content of the checked out directories (by merging files in the directory), or the commit graph is not fully known to TeamCity, and it potentially can affect the checkout.
If you are not running the latest TeamCity release (10.0.5 as of now), it makes sense to update. If you still get merge commits displayed which are not affecting the checked out files and are not merging commits created before the VCS was configured in TeamCity, it makes sense to report the details to TeamCity support.

Bamboo Branch Updater: Is it possible to build the branch isolated first and then merge with master and build again?

I am having a bit of trouble with the Branch Updater feature of Bamboo.
If a new commit is pushed on a branch that is using the branch updater, Bamboo checks if there are new commits on the dependent branch(in my case the master branch) and if this is the case it merges the changes and runs the build.
However, if this build fails, it is hard to recognize, if the new code on the branch itself is broken or if it just could not be merged correctly with the master. Therefore I would like that in these cases the branch is build independently first and only if this build is successful, the changes on the master are merged in and the branch is build again.
Is this possible using the branch updater feature?
A workaround might be to use multiple build plans and use one to build all branches isolated and another plan to integrate everything using the branch updater.
The "Branch Updater" feature is to merge the code from master branch into feature branch after a successful build of the master branch.
However, currently there is NO straight forward option in Bamboo (except the workaround mentioned in your OP) to build the branch and auto merge only if the branch build is successful.
Typically, the developer runs the build in local and commit the changes to repository if the local build is successful. There are two things that can go wrong.
1) While running the local build, the latest code from feature branch is not available in local. Some of the repos like GIT would complain if the local doesn't match with HEAD revision, you need to update to HEAD before you commit the changes. In this case, you can run the build again to ensure there is no problem.
2) When the master code merges with feature branch, something could go wrong
I understand that still there is a gap which can be addressed to resolve the point 2.
You can create a ticket in Bamboo with detailed explanation of the use case to add this feature.

mvn jgitflow:release-finish is merging release --> master --> develop

When I was using
mvn jgitflow:release-finish
I noticed that the release branch got merged into master branch.
Question: Is this the correct way?
Sorry my questions might be naive as I am new to this. I was thinking that the code from release branch will merge to develop and master and not like release --> master --> develop.
Question: What if I don't want this to happen and instead I should be in a position to rebase develop from master?
When I was using mvn jgitflow:release-finish I noticed that the release branch got merged into master branch. Is this the correct way?
This is the correct way according to the main philosophy behind, gitflow:
Release branches
May branch off from:develop
Must merge back into: develop and master
And according to the plugin documentation, the release-finish indeed merges back to the master and dev branch:
finishing a release - runs a maven build (deploy or install), merges the release branch, updates pom(s) with development versions
This makes sense, because (again back to gitflow):
When the state of the release branch is ready to become a real release, some actions need to be carried out. First, the release branch is merged into master (since every commit on master is a new release by definition, remember). Next, that commit on master must be tagged for easy future reference to this historical version. Finally, the changes made on the release branch need to be merged back into develop, so that future releases also contain these bug fixes.
I was thinking that the code from release branch will merge to develop and master and not like release --> master --> develop.
The order follows this flow (first master, then develop) because it's a release and as a release it must firstly go to master (which should always represent the released code base), then to develop (whish is the next potential release code base).
What if I don't want this to happen and instead I should be in a position to rebase develop from master.
You can use the noReleaseMerge option:
Whether to turn off merging changes from the release branch to master and develop
Default value is to false, hence by default merges are performed. However, the option covers the two merges, you cannot disable only one of them, it's either both (again, following gitflow philosophy) or none. This option may suit your needs but you would then perform additional actions via git commands.

JGitFlow maven plugin release-start from custom branch

Is it possible to make a release from custom branch (not develop)?
I tried to use startCommit command, but Maven JGitFlow plugin has been switched to the develop branch before release is started.
Also, when I changed git configuration manually, it was automatically changed to develop.
I would like to use following steps:
release-start - create release branch
release-finish - create tag, merge to the master and develop, update pom.xml versions.
Issue found
Create a branch from tagged version
Fix issues there
Make another release from that branch
It seems that the parameter startCommit (http://jgitflow.bitbucket.org/release-start-mojo.html#startCommit) is not enough because that provokes an exception with m5.1 (https://ecosystem.atlassian.net/browse/MJF-284). Using flowInitContext seems to work though (http://jgitflow.bitbucket.org/release-start-mojo.html#flowInitContext). You just have to adjust the develop branch (source branch for release branches) to point to your custom branch.
The only thing which cannot be achieved that way, is that during release-finish a merge back to the global develop branch is done. Usually you also don't want to merge back to master (since that may provoke git merge conflicts), which need to be resolved manually.

Resources