Fetch from one git server and push to another server using Jenkins - java

I have a local git server (centOS) where everyone pushes their work to that repository. Jenkins manages to build whatever in that repository is, overnight. Lately I've got a Git Enterprise account. I've been wondering if there's any way to force Jenkins to 1) Only pulls the code from the local server and 2) Whenever a build was successful, sends the code to git enterprise remote repository.
I'm using Jenkins v. 1.458

well, one option would be to just create a script that does this from bash...but...
You can just add two git repositories under the "source code management" section after installing the Multiple SCMs plugin, and then specify that you want to build REPOLOCALNAME/branch, and then at the end under 'Git publisher' specify you want to merge and push to the remote branch. (ie. BranchToPush=branchname and TargetRemoteName= REMOTEREPONAME)
*Remember, the names are specified under advanced options of the repository when you add it under the SCM section.
*I haven't tested this, there is a chance that it might let you only pull and push, from and to the same repository.

You could set up the push to Github as the last build step that is only run after everything else has succeeded and use the normal mechanisms for retrieving the code from the local git repository. There is no plugin that has this functionality at the moment.

Related

commit file from a web application (spring boot) into git remote repository without first cloning the repo as local? is this possible

I am sure this must have been solved before, but I could not get a concrete example.
I have a web app which is taking input from user for some config mgmt and creating an XML. The XML is supposed to be checked into a git repo.
Being new to Git a little clueless, all examples point that we need to have a local repository cloned on disk before doing a git add and finally a git commit and git push.
My question is can't we avoid cloning locally and do a git commit and git push programmatically (java) for that given file [myrepo/config/my-config.xml]
Any example really appreciated.
No, you can not do commit and push without local repository.

Playframework, Heroku, RabbitMQ and background workers

My goal is to to set up a horizontally scalable app on Heroku using the Play! framework. The web worker will receive inbound requests from users and will offload the work and run the jobs asynchronously through RabbitMQ to a background worker.
The web worker will be very light weight, however my background workers will be under a lot of load and so will need to scale.
The background workers will just be a Java class which is called from the Procfile as a command. The classes will then listen for messages published by RabbitMQ.
The challenge I'm facing is that I'm quite new to both Heroku and additionally the Play! framework.
My question is it possible/wise to build a scalable application on Heroku in this manner?
And additionally am I handling the background workers in the right approach for use within Play! framework?
Thank you in advance.
The challenge I'm facing is that I'm quite new to both Heroku and additionally the Play! framework.
I can explain you how you can run your project using Play framework on Heroku.
First you should install Heroku toolbelt & Git.
Then open your terminal and configure the git according to your account:
git config --global user.name "yourName"
git config --global user.email "yourgithub#email.com"
git config --global push.default matching
git config --alias.co checkout
Then go to your project folder and type git init. This is going to initialize an empty Git repository. When you commit your code, it's going to be saved in this repository, then you can push it to Github.
Once you initialize Git repository, type git statusto see untracked files. Now you should add files to include in what will be committed: git add .. Dot means "all". Then you are allowed to commit them by typing: git commit -a -m "message". Whenever you make some changes in your code, or add new files, you just need to type git status, then commit them like the way l've just explained.
After you successfully commit your code to Git repository, all you need to do is to create a repository on Github and copy the lines that are for "... or push an existing repository from the command line"
Note: You might need to set your own SSH for both Github and Heroku.
Once you upload your project to the Github, you can now set Heroku for your project. What you need to do is now set Heroku credentials. Then goto your project folder and type heroku create. Once you create heroku for your project, you can type heroku opento see your own heroku page for your project. git push heroku master allows you to push your project that you added to the Git repository to the Heroku. If everything goes well, you can refresh your browser and see that your project works on Heroku.

Our git remote repository is not synchronized with local repository

we have a problem with pushing our local stuff to a remote bitbucket repository.
we are doing commit and push but the changes do not appear in our remote master branch.
Here is the problem in the Git History view of eclipse:
Could somebody please explain to me the difference between refs/remotes/origin/master and refs/heads/master?
In my experience the eclipse git plugin ( in matter of fact most IDE git plugins) is not very reliable. So I would suggest you to try using git command line or some 3rd party solutions like TortoiseGit and try pushing again.
refs/remotes/origin/master contains the SHA-1 of the commit that your local repository believes is the latest on your branch master in your remote origin. It is updated when you communicate with the remote.
refs/heads/master contains the SHA-1 of your latest commit on your local branch master.
See Git references for more info.

How to generated Build number with Git repository using Maven Build number plugin ?

I am configuring maven build number plugin with Git repository in my project, its working fine in my local machine.
If I am building code in my local machine using maven ,so the generated build number is from my local machine or it takes from Git repository ?
As I am using Git repository for Build Number plugin, so is it necessary to give the credentials.
Any help ?
A late answer, and it actually says 'it depends'.
Since git is a distributed version control system once you clone a repository you have the whole history of the project available locally. Push and fetch operations keep remote and local copies in sync.
So now it depends on how exactly the build number plugin is configured to know where it gets the build number from.

Is it possible to trigger Jenkins from one specific branch only?

My situation is the following:
I have three branches in a repo: master, dev and staging.
And I have one job for each one of these branches, configured in 'Branches to build' section in Jenkins. origin/master, origin/dev, origin/staging.
Bitbucket triggers the job to build whenever there are changes to the repository via a repository hook .(https://confluence.atlassian.com/display/BITBUCKET/Jenkins+hook+management).
However, when I push to master, all jobs starts to build, and the same with the other two ones.
I want Jenkins "master" job to be built only when I push to master branch. Jenkins "dev" job to dev branch. Jenkins "staging" job to dev staging.
Is there a way to control this behaviour?
Did you set up polling?
https://wiki.jenkins-ci.org/display/JENKINS/Git+Plugin#GitPlugin-Pushnotificationfromrepository
... This will scan all the jobs that's configured to check out the specified URL, the optional branches, and if they are also configured with polling, it'll immediately trigger the polling (and if that finds a change worth a build, a build will be triggered in turn.) We require the polling configuration on the job so that we only trigger jobs that are supposed to be kicked from changes in the source tree.
I just discovered that Bitbucket does not allow to choose a specific hook when pushing to branches. It just calls all the hooks, then it starts all Jenkins' jobs.
My solution was to create a specific file on my machine, on which Jenkins is installed and set a Bitbucket hook to this file. (e.g. http://{jenkins url}:{apache port}/check.php)
Note that this apache port is not the same of Jenkins', but Apache's. In my case, Jenkins was running at 8080 and Apache at 7777. It did this to run php script, but not in Jenkins' directory.
Since Bitbucket hook sends a json file, I was able to verify in check.php which branch has been pushed on.
Reference: POST hook management
After the verification using a simple 'if', I just called the right url to start the right job with exec_curl, like:
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, http://{jenkins url}:{jenkins port}/job/{job name}/build?token={job token});
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_exec($ch);
curl_close($ch);
And voilĂ .
To have different Jenkis projects for different branches I did the following:
Install Bitbucket Plugin at your Jenkins
Add a normal Post as Hook to your Bitbucket repository (Settings -> Hooks) and use following url:
https://YOUR.JENKINS.SERVER:PORT/bitbucket-hook
Configure your Jenkins project as follows:
under build trigger enable Build when a change is pushed to BitBucket
under Source Code Management select GIT; enter your credentials and define Branches to build (like **feature/*) <- this is where you define different branches for each project
By this way I have three build projects, one for all features, one for develop and one for release branch.
And best of it, you don't have to ad new hooks for new Jenkins projects.
Yes!! You can trigger the jenkins build whenever there is a commit or merge into a specific branch of the git repo.
STEPS:
Configure the webhook for your jenkins instance in the Webhook section of the github Repository, the Payload URl will look similar to,
http://jenkinsinstance:8080/github-webhook/
In the Jenkins Job configuration just enable,
GitHub hook trigger for GITScm polling
Then in the SCM section add the below configuration available in the image, assuming the branch you want to build being the Hotfix branch. The Below image defines the exact configuration of SCM section.
SCM Configuartion image
Once done, try to commit code changes to the Hotfix branch, which in return should trigger the jenkins job.

Categories

Resources