Branch git flow, start, which branch? - devops

So i created a git flow with the command "git flow init".
I'm on develop.
If i do "git flow start feature MY_FEATURE", it's duplicate develop for a feature.
"git flow start feature MY_FEATURE-2" duplicate develop or the branch current?
Thanks you.

"feature start" will always automatically create a feature-branch from the develop-branch called feature/.
"feature finish" will merge the feature-branch back into the develop-branch and delete the feature-branch afterwards.
That's the way this convention works
Have a look at this graphic for better understanding
How feature-branches in gitflow work

Related

I can't use push_to_git_remote() in fastlane

I have an issue with gitlab, gitlab-ci and fastlane. In fastlane, I am using :
def increment_build_and_commit
incrementBuildNumber()
commit_version_bump(message: 'build number bump [skip ci]')
push_to_git_remote(
remote: 'origin_rw',
remote_branch: ENV['CI_COMMIT_BRANCH']
)
end
So I want to increase build number and commit. So it does the job with:
incrementBuildNumber(),
commit_version_bump(message: 'build number bump [skip ci]')
But when running, it fails at push_to_git_remote
[!] Exit status of command 'git push origin_rw HEAD:HEAD --tags
--set-upstream' was 1 instead of 0. error: The destination you provided is not a full refname (i.e., starting with "refs/"). We
tried to guess what you meant by:
Looking for a ref that matches 'HEAD' on the remote side.
Checking if the being pushed ('HEAD') is a ref in "refs/{heads,tags}/". If so we add a corresponding
refs/{heads,tags}/ prefix on the remote side. Neither worked, so we
gave up. You must fully qualify the ref. hint: The part of the
refspec is a commit object. hint: Did you mean to create a new branch
by pushing to hint: 'HEAD:refs/heads/HEAD'? error: failed to push
some refs to '**********.git'
Some of you have any clues what to do and how to solve this problem? As I am going to be a google machine on that, but unfortunetly can't find the solution.
Thanks in advance!!
This happens because gitlab-ci checkouts git commit instead of git branch and you enter detached HEAD state.
There are few ways to get around this:
1) Use CI provided value. For GitLab I would recommend using CI_PIPELINE_IID. Downside is that you cannot control it and if you migrate your project to other repository it will start from 1 again.
2) Checkout git branch before making commit. Downside is that if other developer pushes to the same branch, your pipeline will continue with wrong source code.
3) Commit version number bump manually.

Bitbucket - How to enforce that merges are done first to Develop branch and then to Master branch?

Gitflow workflow states that Hotfix branches will be merged to both Develop and Master branches.
Since engineers forgot more than once to merge their hotfix to Develop, I want to mandate that the merge to develop is done first.
How can I configure Bitbucket to block merges of commits, that do not already exist in Develop, to master?
I don't know about BitBucket, but if you're able to install your own hooks, it's easy enough to script whatever you want in a pre-recive or update hook.
The following is an (untested) example, there are perhaps more efficient git commands to accomplish this, I'm not sure.
#!/bin/bash
# ... << Code to set up your hook variables here >>> ...
if [ "$(git branch Develop --contains $new_rev | wc -l)" -eq 0 ]; then
echo "ERROR: You must commit to Develop first and then merge"
exit 1
fi
exit 0

How can I create a jenkins job, who must execute test on commit?

I'm beginning with Jenkins.
I want, that each time I do a git commit (or push?), that the jasmine test of my ionic project was executed and must work before the commit can be done.
In reality, it has 2 questions:
How execute jasmine test with Jenkins?
In this moment I execute the test with:
npm test
How can I do for executing this tests with a commit (or a push)?
Thanks
Best regards
You have two ways to achieve the task.
GIT Hook: From GIT after commit or push execute the Jasmine test
Jenkins Trigger with GIT Hook: From Jenkins check the repo and execute the Jasmine test
Hooks from GIT
Look for the hidden directory in your git repo, you'll find a directory called "hooks" and inside it many examples of hooks:
First list the content of your repo main directory:
ls -ltra
You should see something like:
m.ortiz.montealegre#CPX-XYR3G1DTHBU ~/-argentina/.git
$ vim hooks/
applypatch-msg.sample pre-applypatch.sample pre-push.sample update.sample
commit-msg.sample pre-commit.sample pre-rebase.sample
post-update.sample prepare-commit-msg.sample pre-receive.sample
You have a whole guide of how to setup hooks here.
In your case maybe update would do the thing:
update The update script is very similar to the pre-receive script,
except that it’s run once for each branch the pusher is trying to
update.
Triggers from Jenkins with GIT Hooks
In this one you'll setup your Jenkins project build trigger with "Poll SCM" but do not specify a schedule.
Then with a post-receive hook from GIT notify the Jenkins Job about the changes:
http://yourserver/jenkins/git/notifyCommit?url=<URL of the Git repository>?token=<get token from git to build remotely>
I found that example here.
Run the Jasmine tests
I don't know which O.S you're using but I hope it's a beautiful Linux box.
You can achieve pretty much the same with Jenkins. You need to consider the user (your user) and its permissions and check if the user which runs the Jenkins instance is allowed to execute the same.
Just create a new Jenkins Project and add a shell execution step with the test just like you said:
npm test
There are many questions regarding your particular environment, but I think that this will be a good guide for you.
There was a ticket about adding this functionality.
Finally the ticket was closed
slackersoft commented on 2 Dec 2016
At this point, I think it makes more sense to leave the code to do the watching of your specs and production code to one of the many external libraries that are built specifically for that.
The relate external library can be:
jasmine-node
nodemon
mochajs
gaze

Get git branch name with gradle git plugin on jenkins slave

I'm doing sonar integration and would like to pass git branch as a parameter. It will be run on Jenkins server.
Before I was using next line of code to get current git branch:
def workingBranch = """git rev-parse --abbrev-ref HEAD""".execute().text.trim()
After I replaced it with:
grgit.branch.current.fullName
But this always gives me "HEAD". How to achieve same functionality?
I am doing something very similar. As it turns out, the Git plugin in Jenkins is tuned in several ways to minimize the git clone and checkout. There are 2 ways that I've found to deal with this.
The Easy Way
Use Jenkins' built-in environment variables, as you already suggested in the comments.
def workingBranch = System.getenv("GIT_BRANCH") ?: grgit.branch.current.fullName
The Job Configuration Way
You can also set up the job to checkout the branch as a local branch, rather than a detached HEAD. This is under "Additional Behaviors", named "Check out to specific local branch". There are many other questions that detail the settings for that, and/or the Declarative Pipeline approach, depending on what your needs.
Declarative Pipeline custom checkout
Configuring local branch option

Keep track of which git branch is currently deployed to a Heroku server

I know there is a http deploy hook I can use but unfortunately it does not submit the branch name, here is what it does submit:
{"head"=>"7021419", "app"=>"appname", "git_log"=>"commit message", "action"=>"home", "url"=>"site url", "prev_head"=>"1d844b0", "controller"=>"account_sessions", "user"=>"heroku#user.com", "head_long"=>"7031429230228988d8f3312fa9e74d77b6c1bc14"}
I tried using the head or head_long to figure out the branch name with:
git branch --contains SHA
Which worked, but it is not 100% accurate as the same SHA could be in multiple branches. Same can be said about:
git reflog show --all | grep 7021419
I am pretty sure it is impossible to get the current branch name from within the deployed app as the branch deployed to Heroku is always the "master" branch. I was hoping I can send the deploy callback hook to another server and store the deployment record somewhere.
1. Detecting only
If it's just about heads, use
git rev-list --no-walk --glob=refs/heads
with a bit of --format and grep logic tacked on
2. Tracking locally
The simplest way would be using a tag.
Push the tag like a normal branch:
git push herokuremote tagname:publicbranchname
Unfortunately, that would just push the tag, not a branch... ; read on for alternative
(note I don't know/use heroku, so I don't know the naming conventions, sorry)
3. Symbolic branch reference
If you don't mind using a bit of plumbing, you can name a local ref as the one deployed. You can have a symbolic ref for the purpose:
git update-ref -m "deployed release candidate" --no-deref refs/heads/deployed master
If the same SHA is in multiple branches, they are effectively the same branch (at least at that point in time). If you're sure that SHA is the last commit of a branch, you can find it in .git/refs/heads/* where * is a list of files whose names correspond to branch names and contents are the SHAs.
It seems like you might be able to solve this recording problem by not using their API. Wrapping your deploy script (or Heroku's deploy binary, or a post-push hook) should give you the flexibility you need to notify a different service for record keeping.

Resources