I've installed the plugin Gerrit Trigger on Jenkins cos I need to start automatically the building when a developer in the team pushes something on the repository (relative to a specific project). I followed the settings here:
https://wiki.jenkins-ci.org/display/JENKINS/Gerrit+Trigger
The test connection is ok. Anyway when something is pushed the building doesn't "trigger". The only thing I can see is:
Under "Manage Jenkins" -> The connection to Gerrit is down! Check your settings and the Gerrit server.
any idea?
thanks
randomize
BTW I got this:
BTW I got this: Command "git fetch -t git#github.com:somewhere/MyProject.git $GERRIT_REFSPEC" returned status code 128: fatal: Couldn't find remote ref $GERRIT_REFSPEC
fatal: The remote end hung up unexpectedly
ERROR: Could not fetch from any repository
FATAL: Could not fetch from any repository
hudson.plugins.git.GitException: Could not fetch from any repository
at hudson.plugins.git.GitSCM$2.invoke(GitSCM.java:1008)
at hudson.plugins.git.GitSCM$2.invoke(GitSCM.java:968)
at hudson.FilePath.act(FilePath.java:758)
at hudson.FilePath.act(FilePath.java:740)
at hudson.plugins.git.GitSCM.checkout(GitSCM.java:968)
at hudson.model.AbstractProject.checkout(AbstractProject.java:1184)
at hudson.model.AbstractBuild$AbstractRunner.checkout(AbstractBuild.java:537)
at hudson.model.AbstractBuild$AbstractRunner.run(AbstractBuild.java:425)
at hudson.model.Run.run(Run.java:1376)
There is trick described on the Gerrit plugin page:
Normally when you have configured a job to be triggered by Gerrit you can't use the "Build Now" link anymore since your builds are dependent on information from Gerrit, especially if you are using the Git plugin to checkout your code in the workspace.
You can get around this limitation if you for example want to use the same job to build the master branch at some point. If you are using the Git plugin do the following
Add a String parameter called GERRIT_REFSPEC with the default value refs/heads/master
Using this trick will enable you to build, but no results will be sent to Gerrit since tit is not triggered by it.
That doesn't work with the Gerrit trigger, because then the variable $GERRIT_REFSPEC isn't set. If you want to manually trigger a changeset from Gerrit, you have to use the "Query and Trigger Gerrit Patches". There you can search for open changes in Gerrit and build them.
You should also notice, that a build is only triggered, if you have pushed the changes to the review branches in Gerrit, e.g. a refs/for/ reference. If you pushed directly to the branches (e. g. refs/heads/master), because you don't want to do code review, the Gerrit trigger doesn't work. You would have to use one of the Gerrit hooks, that calls a URL which starts a build or let the build job poll your Git repository.
in our case, we had to restart the jenkins service. this looks to be a bug with the gerrit trigger plugin (we're on 2.27.5)
You Need to start the gerrit server from the jenkin>> gerrit trigger> click on status icon.
Related
I'm trying to make push inside an existing repository in Github using the following command,
git push -u origin master
I get the following errors,
To https://github.com/Chaklader/Technical-Interview.git
! [rejected] master -> master (non-fast-forward)
error: failed to push some refs to 'https://github.com/Chaklader/Technical-Interview.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Integrate the remote changes (e.g.
hint: 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
AS it suggested, I tried to make a pull using the following command,
git pull origin master
That seems doesn't work either. How to resolve the issue ?
I made a silly mistake and had no commit in the Github and thus the problem started.
git commit -m "added some examples for the design patterns (Observer, Visitors, Proxy etc)"
Afterwards, there was no issue with the push command.
Your local master branch is behind the remote branch.
before adding local changes .first sync with remote using
git pull
(check using git log --oneline ) .It should match with remote changes
yourmaster branch log like this now.
a570f1e design aptterns
607f53c added different deign patterns
c586b42 Update mySyntax.cpp
17ffb35 Update README.md
66e75d3 Update README.md
e66d701 update
3344773 first commit
0bd776c first commit
c1a0898 first commit
2468750 first commit
on top of above commit your local changes .then push using (push to remote master branch)
git push origin HEAD:refs/for/master
You can reset your changed files and stash them at first:
git rest HEAD^
git stash
Then pull from remote repository:
git pull
Then pop up stashed files:
git stash pop
Then add all files and commit and push to remote repository.
git add .
git push origin master
I need to sequentially check out tags over a branch I created with JGit.
CheckoutCommand checkout = new Git(testRepository).checkout();
if (!branchExists())
checkout.setCreateBranch(true).setName("branch-for-test").setStartPoint(key);
else
checkout.setName(key);
checkout.call();
Where key is a String which contains the name of the commit I want to checkout (key changes in a loop). I don't want to create a branch each time I checkout as I don't need to. The following error is shown:
org.eclipse.jgit.api.errors.JGitInternalException: Could not rename file target\TestRepository\server\db\scripts\postgresql\._db_script.sql6197897692249726905.tmp to target\TestRepository\server\db\scripts\postgresql\_db_script.sql
at org.eclipse.jgit.api.CheckoutCommand.call(CheckoutCommand.java:320)
Before this happened I was trying to checkout inside the else statement with
checkout.setName("branch-for-test").setStartPoint(key);
It did not throw any error but it did not checkout the tag either.
Well, it seems that using JGit in Windows may generate conflicts related to managed files sometimes. What I made for solving this recurrent issue was to execute a git clean --force followed by a git reset --hard before each git checkout <ref_name>. This was totally fine for me, as I didn't need to stage changes...
The problem was that basically after using some files (even in a read-only way), they were marked as changed (I verified it with git status). The solution explained above implied more operations, but totally solved my problem.
For further details, refer to git documentation about these actions:
Git clean: Removes untracked files from the working tree.
Git reset: Resets current HEAD to the specified state.
And develop the appropiate implementation of these two actions with JGit:
Clean with Clean Command.
Reset with Reset Command
I am fairly new to git, and I have a problem. I have created couple branches on my git repository and whenever I use git-checkout ant task
to move to a certain branch:
<git-checkout src="./myrepo" branch="origin/mybranch" />
it shows the correct content of that branch in my repository but when I run git branch from the command line it says that its "(detached from origin/mybranch)". After checking out I want to add some files to it, commit and push to remote with some custom ant tasks I wrote, but I'm not able to push because the branch I'm on is detached. How should I fix this?
Thank you for answers
We have Jenkins installed using GitPlugin to pull branches and merge them, as described in the GitPlugin Wiki. However, when the merge fails there's no output saying why it failed, just that it didn't merge cleanly:
<snip>
Seen branch in repository origin/HEAD
Seen branch in repository origin/labs/intro
Seen branch in repository origin/master
Commencing build of Revision 620c4373792b8cef6a3992b6676892479ed379b0 (origin/REV_4/REV-1234)
Merging Revision 620c4373792b8cef6a3992b6676892479ed379b0 (origin/REV_4/REV-1234) onto REV_4/integration
ERROR: Branch not suitable for integration as it does not merge cleanly
[JaCoCo plugin] Collecting JaCoCo coverage data...
<snip>
I can't duplicate this behavior locally. It has something to do with the Git line ending settings.
Can anybody tell me how to squeeze more information out of Jenkins and the GitPlugin, so I can tell what files are failing?
There probably isn't a way, since there's an open issue about it, and also by looking at the source code at least I don't see exception details recorded anywhere. They're lost.
Some options what you could do:
merge the branch yourself and see if it helps
make a fork of the plugin that saves the information somewhere or outputs it or
run Jenkins using remote debugger, having a breakpoint at that point in code.
There are instructions here to run Jenkins with a debugger:
Add the following to the JENKINS_JAVA_OPTIONS variable (separated by
spaces, surrounded by quotes):
-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=5678
So the full line may look something like:
JENKINS_JAVA_OPTIONS="-Djava.awt.headless=true -DXX:MaxPermSize=512m -DXX:+HeapDumpOnOutOfMemoryError -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=0"
Obviously change the port from 5678 to something else if you need.
GIT Plugin prompts this error when there are file conflicts after git merge.
try locally merging both the branches and you can see.
One solution that can be used here is to perform git merge using ours/theirs strategies
git checkout master
git merge -X ours REV-1234
This will allow you to keeps current branch file-revisions for conflicting files.
git checkout master
git merge -X theirs REV-1234
This will allow you to keeps remote branch file-revisions for conflicting files.
tl;dr JGit's checkout throws exceptions while command line git checkout works fine
I'm currently trying to use JGit to check out certain revisions from an online Git repository, in Java (for work). My current approach is (and I'm very new to Git, coming from a SVN background, so this may be wrong):
clone the repository to a temporary location on my hard drive
figure out which revision I want, (I have tried using the SHA-1 hash as well as the name of a branch)
checkout that revision
from there, I would be using the checked out files as inputs to a later part of the program.
checkout a different revision
use those files as inputs to another part of the program
Essentially, I want to be able to swap the contents of my temp folder with whichever revision. With the command line interface I've been able to do this with git checkout master and git checkout dylanbranch (where dylanbranch is a branch I made on my own clone with an arbitrarily chosen revision), but my Java code attempting to do the same thing fails:
Git git = Git.open(new File("checkout")); //checkout is the folder with .git
git.checkout().setName("master").call(); //succeeds
git.checkout().setName("dylanbranch").call(); //fails
And the exceptions printed to the console:
Exception in thread "main" org.eclipse.jgit.api.errors.JGitInternalException: Checkout conflict with files:
src/sizzle
test/qunit
at org.eclipse.jgit.api.CheckoutCommand.call(CheckoutCommand.java:211)
at com.avi.scm.git.BranchCheckout.main(BranchCheckout.java:30)
Caused by: org.eclipse.jgit.errors.CheckoutConflictException: Checkout conflict with files:
src/sizzle
test/qunit
at org.eclipse.jgit.dircache.DirCacheCheckout.checkout(DirCacheCheckout.java:387)
at org.eclipse.jgit.api.CheckoutCommand.call(CheckoutCommand.java:162)
... 1 more
I can verify that the files in question are marked as deleted and not staged for commit by using git status though I'm not sure why those changes are there, and they come back any time I switch back to the master branch. Despite that, I can still successfully change the working tree with command line Git.
So my question: Why won't JGit work for this application when command line git will?
Any other helpful information is appreciated- educate me :)
Update I've been testing with the jQuery repository, and have noticed a few more problems with JGit: When I am working with the "master" branch, git status temms me that I'm #On branch master and that there is nothing to commit (working directory clean), but using JGit's status command I see that test/qunit and src/sizzle are marked as Missing. JGit's reset seems to do nothing.
The two directories mentioned in the stack trace are Git submodules (test/qunit and src/sizzle) which is most likely the cause of the problem since JGit does not have full submodule support yet.
This may function differently in the 1.1 JGit release due out this month based on this commit.
You can read more about the current state of JGit submodule support here.
I know this doesn't directly answer your question, but I've also had problems with the Java implementations of Git. What worked best for me was to simply ditch the java implementations, and execute command-line calls to git from within the application. It may not be ideal, but it'll do exactly what you want since you'll fully control the command.
Simply call
Runtime.getRuntime().exec(...)
Link to Javadoc for Runtime class
I had a similar problem with Checkout. I think that the fact that you can switch branch with unstaged content in Git is actually a tolerance, not a feature.
JGit is globally not as tolerant as Git, so you should usually test many cases.
It seems it is not directly your problem (which is related to the submodules), but for more general cases you would want to commit your changes before using checkout to switch to another branch.
Note that the CheckoutCommand works perfectly for me to start a new branch from an old revision (you have to set the name of the branch and the start revision).