Got error trigger Jenkins builds by pushing to Github - github

I config Jenkins deploy PHP app by trigger the script deployment whenever developers pushed their code to Github with domain .mydomain.com. If developer create new branch and push some changes to that branch, it works perfectly fine, the strange thing is when developer create new branch and push to server (don't change anything just
create new branch and push) it doesn't trigger the script deployment.
Could you please help?

In Git configuration there is a field Branch Specifier (blank for default): if you put there ** it will build all branches from all remotes.
But if you are creating a new branch and push to server it won't trigger the job. As Github plugin in Jenkins configuration is monitoring the changes in the repo and creating a branch is not a change. So the job won't trigger for that branch until you do a commit in that branch. And I feel this is the correct behavior.
For example when you do a commit xxxx on branch master, your job
gets triggered with commit id xxxx. Now you create a branch say
branch1 from master and you push to server. As you can see there is
not difference between commit xxxx and branch1 so there is no need
to build branch1 in Jenkins.

Related

How to trigger azure pipeline in one topic branch during push for another topic branch

My azure devops pipileine's yaml file is not in master branch of bitbucket. Its in another branch inside master branch (master/pipeline-branch). I am trying to trigger that build when there is a push to another topic branch which is also not the master branch. (master/topic/secondary).
In my yaml file I have written the trigger like this.
trigger:
- topic/secondary
But no build is triggered when I push a file to secondary branch.
you need to cherry pick\merge commits with this file to the secondary branch or just commit the yaml file to the secondary branch. when a commit is made a decision to start the build or not is being made by evaluating the yaml file inside the branch a commit was made to. if the file doesnt exist in that branch - there is nothing to trigger

How to review the changes before push into VSTS?

I would like to know,is there any option in VSTS or how to review the changes before pushing the code into VSTS git. Please help here.
Without sharing the code by pushing it to VSTS there is no way other people can look at it. VSTS however does have build in pull requests. This allows you to push your code as a separate branch and then have formal review process before accepting the merge of your changes.
You can find more info in the documentation: Review code with pull requests
You can use below commands to review the changes before pushing:
First, before reviewing the changes in your local repo, you should make sure all the commits from remote repo are pulled in you local repo. You can use the command git pull at first.
Then you can review the changes between your local branch (assume it’s master branch here) master and origin/master.
To review the commits which are not pushed to remote branch
git log origin/master..master --oneline
It will show the commits you made on local master branch but not push to remote repo yet.
To review the changed files between local master branch and remote master branch
git diff origin/master master
It will list the difference for each changed file by comparing master with origin/master.

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.

How to script GIT MERGE commands to automate it in GitLab

My requirement is little different from regular branch merge.
It is something like
Branches in my local and server repo -> Branch-1, Branch-2 & Master
On the event of…
creating a merge request.
pushing changes to the head/source branch
pushing changes to the base/target branch
…do…
attempt a merge of the HEAD/source onto the target.
EG: (git clone target, git remote add source..., git fetch source. git checkout -b attempted-merge; git merge..)
push a new ref to the repo “refs/merge-requests/{id}/head” (git push origin target/:merge-requests/{id}/head)
If there were no merge conflicts, push “refs/merge-requests/{id}/merge” (git push origin attempted-merge:merge-requests/{id}/merge)
Comment on the merge request with the status (using :+1: or :-1: to include a vote of approval)
In this process we are creating a new branch called ATTEMPTED-MERGE. But this branch while pushed should not exactly be pushed to the server instead it should be given a new REFS name (EG: refs/merge-request/{ID}/merge).
So this would actually contains the merge but is not been pushed to the server instead stored in a temporary location where it can been seen in local repo but not in remote repo. This is because of validating the merge and authorizing the merge to actually happen if everything is correct (means if all the code is there as expected and ready for a clean merge). Then once approved it will be merged on the remote repo.
This is the scenario which i have right now. Not able to understand how to do this in SCRIPT and make it automate so that this script should run when a merge is requested.
Inputs to this script are
Source URL, Source Branch, Target URL & Target Branch.
Once these are given the script should run and depending on the input values it should perform the merge in GITLAB.
Can any one help me out how to do this .. !!!!

Jenkins not building new branch on first push

I am using the github plugin in Jenkins and my automatic builds are working for the most part. However, a build only occurs after the second push to a branch. When I create a new branch using git push origin branch_name:branch_name the jenkins build is not kicked off. I have to make another commit to the same branch for that to work. How can I fix this?
It turned out that my new branch was no different than my old branch so it wasn't viewed as a change. As in it had the same commit history with no additions.
I literally just did
git branch -b new_branch
git push origin new_branch:new_branch
The web hook log showed that jenkins recognized the new branch but said --> no changes.