Verigreen / verigreen

Verigreen is a lightweight, server side solution for verification of git commits. It is a gated check-in process which will not allow any failed CI commit to go into an integration/release/any protected branch. We keep it green (hence the name).
Apache License 2.0
57 stars 19 forks source link

Failed to fetch from [refs/remotes/origin/*] to [refs/heads/*] #122

Closed persiarash closed 8 years ago

persiarash commented 8 years ago

Hello,

I have setup my collector as a docker container, and have a separate docker container running bitbucket, hosting my repository, with the hook correctly configured.

When I push a change to my protected branch, the collector gets invoked and creates a new branch with my changes. However my connected Jenkins job is never executed, and my push request fails in this manner:

root@myserver:/repo/arashtest# git push
warning: push.default is unset; its implicit value has changed in
Git 2.0 from 'matching' to 'simple'. To squelch this message
and maintain the traditional behavior, use:

  git config --global push.default matching

To squelch this message and adopt the new behavior now, use:

  git config --global push.default simple

When push.default is set to 'matching', git will push local branches
to the remote branches that already exist with the same name.

Since Git 2.0, Git defaults to the more conservative 'simple'
behavior, which only pushes the current branch to the corresponding
remote branch that 'git pull' uses to update the current branch.

See 'git help config' and search for 'push.default' for further information.
(the 'simple' mode was introduced in Git 1.7.11. Use the similar mode
'current' instead of 'simple' if you sometimes use older versions of Git)

Counting objects: 2, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (2/2), 274 bytes | 0 bytes/s, done.
Total 2 (delta 0), reused 0 (delta 0)
remote: In etcprofile, JAVA_HOME: /usr/lib/jvm/java-7-openjdk-amd64/jre
remote: /bin/bash: /root/.bash_profile: Permission denied
remote: daemon
remote: Script name: /var/atlassian/application-data/bitbucket/bin/git-hooks/sample-hook.sh
remote: JAVA_HOME: /usr/lib/jvm/java-7-openjdk-amd64/jre
remote: VG_HOOK: /var/atlassian/application-data/bitbucket/verigreen
remote: Oldrev: bab7e146d705a659a6604467af38963d8d5f0ffd Newrev: 864f11279a2d392b100f0ba3fd2a2b2125bc79cb Ref: refs/heads/master
remote: =======================================
remote:
remote:
remote: Submitted for verification by Verigreen
remote:
remote:
remote: =======================================
remote:
remote:
remote: Verigreen returned: 1
remote: /var/atlassian/application-data/bitbucket/bin/git-hooks/sample-hook.sh: line 30: /root/.bash_logout: Permission denied
To ssh://git@10.25.115.212:7999/evd/arashtest.git
 ! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to 'ssh://git@10.25.115.212:7999/evd/arashtest.git'

I'm using this script to setup my collector (showing relevant parts):

SERVICE_NAME="verigreen" # the service name (case sensitive, of course!). Should be the same as this script name

# All parameters below are for the docker HOST machine, not the container!
VG_NAME="myvg"
REPO_NAME="myrepo"

REPO_DIR="/DATA/gitrepo/$REPO_NAME" # may need to manually clone to this location
SSH_DIR="/root/.ssh" # SSH keys to authenticate git operations within the repository
CONFIG_DIR="/DATA/VG" # config.properties and run.yml files are placed here
DOCKER_IMAGE="verigreen/vg-collector"
PORT=8085
# Limit container logs (via json-file log file) to 10k. Adjust as needed
LIMIT_DOCKER_LOG="--log-driver json-file --log-opt max-size=10k --log-opt max-file=10"
RESTART_OPT="--restart=always"

#*******************************************************************************
# start, stop, status functions
function SERVICE_START() {
    /usr/bin/docker run -d \
      $RESTART_OPT \
      $LIMIT_DOCKER_LOG \
      --hostname="$VG_NAME" \
      --name="$VG_NAME" \
      -v $SSH_DIR:/ssh \
      -v $CONFIG_DIR:/vg \
      -v $REPO_DIR:/DATA/gitrepo/myrepo \
      -p $PORT:8080 \
      $DOCKER_IMAGE

    sleep 3
    SERVICE_STATUS
}

My /DATA/VG/config.properties file looks like this (showing relevant parts, other parts unchanged):

# Jenkins Configuration
jenkins.url=http://10.25.115.95:8080/
jenkins.user=root
jenkins.password=password
##############Changes in this field will be effected after save (no restart is needed)################
#Warning! Do not change the jobName parameter while there are commits being verified in the system!
jenkins.jobName=verigreendemo
jenkins.branchParamName=SCM_BRANCH
#The maximum number of seconds Verigreen waits for a verification build to complete.
jenkins.timeoutInSeconds=3600

# Git configuration
git.repositoryLocation=/repo
##############Changes in this field will be effected after save (no restart is needed)################
git.protectedBranches=refs/heads/master
##############Changes in this field will be effected after save (no restart is needed)################
git.permittedUsers=

#JGitOperator configuration
#These sets Verigreen's user.name and user.email git configuration parameters.
commited.by.collector=VeriGreen
email.address=my@email.com

# Mail Configuration
#The SMTP server Verigreen will use to send its emails.
#SMTP authentication is not currently supported.
mail.server=10.25.115.212

#Collector Display Name
collectors=My VeriGreen
#The URL of the Verigreen collector.
#This is the address that need be configured in the Verigreen git-hook configuration file, hook.properties.
# Add /<warName> after the port number, if deployed as war.
#This parameter is required for Verigreen to work.
#forexamplecollector.address=<CollectorHost>:<CollectorPort>/rest
collector.address=10.25.115.212:8085/rest

And finally my /DATA/VG/run.yml file looks like this:

repository:
# please provide the git remote repository url used in git clone (e.g. ssh://<user>@<domain>:<port>/path/to/repo.git)
remote_url: "ssh://git@10.25.115.212:7999/evd/arashtest.git"

As you can see, branches are automatically created in my bitbucket: image

And jobs are started, but fail with GIT_FAILURE on the collector's UI: image

Here is the exception in the collector's logs:

19/11/16 04:51:04:004 INFO  [com.verigreen.collector.common.log4j.VerigreenLogger] *** com.verigreen.collector.jobs.CallJenkinsJob::calllingJenkinsForCancel (tid: 24) *** There are [0] not canceled items...
 *** END ***
19/11/16 04:51:04:004 INFO  [com.verigreen.collector.common.log4j.VerigreenLogger] *** com.verigreen.collector.decision.decisionmaker.ProtectedBranchesDecisionMaker::decide (tid: 23) *** There are 1 not done item(s)
 *** END ***
19/11/16 04:51:04:004 INFO  [com.verigreen.collector.common.log4j.VerigreenLogger] *** com.verigreen.collector.decision.DecisionExecuter::doExecute (tid: 23) *** Going to run decision (Decision [_commitItemId=0825882e-baff-4664-aac6-140d54bbed0d, _handler=class com.verigreen.collector.decision.CheckinDecisionHandler])
 *** END ***
19/11/16 04:51:04:004 INFO  [com.verigreen.collector.common.log4j.VerigreenLogger] *** com.verigreen.collector.decision.CheckinDecisionHandler::doUpdateBranch (tid: 23) *** Going to merge branch with latest changes... (vg_6dfa167_Veri_Green)
 *** END ***
19/11/16 04:51:04:004 ERROR [com.verigreen.collector.common.log4j.VerigreenLogger] *** com.verigreen.collector.decision.CheckinDecisionHandler::updateBranch (tid: 23) *** Failed updating branch [vg_6dfa167_Veri_Green] *** END ***
java.lang.RuntimeException: Failed to fetch from [refs/remotes/origin/*] to [refs/heads/*]
        at com.verigreen.jgit.JGitOperator.fetch(JGitOperator.java:152) ~[verigreen-collector-api-2.5.6.jar:?]
        at com.verigreen.jgit.JGitOperator.fetch(JGitOperator.java:167) ~[verigreen-collector-api-2.5.6.jar:?]
        at com.verigreen.collector.decision.CheckinDecisionHandler.updateProtectedBranch(CheckinDecisionHandler.java:134) ~[verigreen-collector-impl-2.5.6.jar:?]
        at com.verigreen.collector.decision.CheckinDecisionHandler.createMergedBranch(CheckinDecisionHandler.java:96) ~[verigreen-collector-impl-2.5.6.jar:?]
        at com.verigreen.collector.decision.CheckinDecisionHandler.doUpdateBranch(CheckinDecisionHandler.java:80) ~[verigreen-collector-impl-2.5.6.jar:?]
        at com.verigreen.collector.decision.CheckinDecisionHandler.updateBranch(CheckinDecisionHandler.java:57) [verigreen-collector-impl-2.5.6.jar:?]
        at com.verigreen.collector.decision.CheckinDecisionHandler.doHandle(CheckinDecisionHandler.java:39) [verigreen-collector-impl-2.5.6.jar:?]
        at com.verigreen.collector.decision.DecisionHandler.handle(DecisionHandler.java:29) [verigreen-collector-impl-2.5.6.jar:?]
        at com.verigreen.collector.decision.DecisionExecuter.doExecute(DecisionExecuter.java:40) [verigreen-collector-impl-2.5.6.jar:?]
        at com.verigreen.collector.decision.DecisionExecuter.execute(DecisionExecuter.java:27) [verigreen-collector-impl-2.5.6.jar:?]
        at com.verigreen.collector.jobs.ConsumerJob.execute(ConsumerJob.java:29) [verigreen-collector-impl-2.5.6.jar:?]
        at org.quartz.core.JobRunShell.run(JobRunShell.java:202) [quartz-2.2.1.jar:?]
        at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:573) [quartz-2.2.1.jar:?]
Caused by: org.eclipse.jgit.api.errors.InvalidRemoteException: Invalid remote: origin
        at org.eclipse.jgit.api.FetchCommand.call(FetchCommand.java:134) ~[org.eclipse.jgit-3.0.0.201306101825-r.jar:3.0.0.201306101825-r]
        at com.verigreen.jgit.JGitOperator.fetch(JGitOperator.java:150) ~[verigreen-collector-api-2.5.6.jar:?]
        ... 12 more
Caused by: org.eclipse.jgit.errors.NoRemoteRepositoryException: origin: not found.
        at org.eclipse.jgit.transport.TransportLocal$1.open(TransportLocal.java:130) ~[org.eclipse.jgit-3.0.0.201306101825-r.jar:3.0.0.201306101825-r]
        at org.eclipse.jgit.transport.TransportBundleFile$1.open(TransportBundleFile.java:105) ~[org.eclipse.jgit-3.0.0.201306101825-r.jar:3.0.0.201306101825-r]
        at org.eclipse.jgit.transport.Transport.open(Transport.java:554) ~[org.eclipse.jgit-3.0.0.201306101825-r.jar:3.0.0.201306101825-r]
        at org.eclipse.jgit.transport.Transport.open(Transport.java:314) ~[org.eclipse.jgit-3.0.0.201306101825-r.jar:3.0.0.201306101825-r]
        at org.eclipse.jgit.transport.Transport.open(Transport.java:285) ~[org.eclipse.jgit-3.0.0.201306101825-r.jar:3.0.0.201306101825-r]
        at org.eclipse.jgit.api.FetchCommand.call(FetchCommand.java:118) ~[org.eclipse.jgit-3.0.0.201306101825-r.jar:3.0.0.201306101825-r]
        at com.verigreen.jgit.JGitOperator.fetch(JGitOperator.java:150) ~[verigreen-collector-api-2.5.6.jar:?]
        ... 12 more
19/11/16 04:51:14:014 INFO  [com.verigreen.collector.common.log4j.VerigreenLogger] *** com.verigreen.collector.jobs.CallJenkinsJob::calllingJenkinsForUpdate (tid: 25) *** Jenkins called for update on [0] not updated items...
 *** END ***
19/11/16 04:51:14:014 INFO  [com.verigreen.collector.common.log4j.VerigreenLogger] *** com.verigreen.collector.jobs.CallJenkinsJob::calllingJenkinsForCreate (tid: 25) *** There are [0] not triggered items...
 *** END ***
19/11/16 04:51:14:014 INFO  [com.verigreen.collector.common.log4j.VerigreenLogger] *** com.verigreen.collector.jobs.CallJenkinsJob::calllingJenkinsForCancel (tid: 25) *** There are [0] not canceled items...
 *** END ***
19/11/16 04:51:14:014 INFO  [com.verigreen.collector.common.log4j.VerigreenLogger] *** com.verigreen.collector.decision.decisionmaker.ProtectedBranchesDecisionMaker::decide (tid: 17) *** There are 1 not done item(s)
 *** END ***
19/11/16 04:51:14:014 INFO  [com.verigreen.collector.common.log4j.VerigreenLogger] *** com.verigreen.collector.decision.DecisionExecuter::doExecute (tid: 17) *** Going to run decision (Decision [_commitItemId=0825882e-baff-4664-aac6-140d54bbed0d, _handler=class com.verigreen.collector.decision.OnFailureHandler])
 *** END ***
19/11/16 04:51:14:014 INFO  [com.verigreen.collector.common.log4j.VerigreenLogger] *** com.verigreen.collector.decision.OnFailureHandler::doHandle (tid: 17) *** Commit (vg_6dfa167_Veri_Green) verification completed with failure (Failed due to git failure, could be a techincal issue)
 *** END ***

From within my collector, showing the repo and git config:

root@myvg:/app# cd /repo
root@myvg:/repo# git status
On branch master
Your branch is up-to-date with 'origin/master'.
nothing to commit, working directory clean
root@myvg:/repo# git remote -v
origin  ssh://git@10.25.115.212:7999/evd/arashtest.git (fetch)
origin  ssh://git@10.25.115.212:7999/evd/arashtest.git (push)
root@myvg:/repo# git config -l
core.repositoryformatversion=0
core.filemode=true
core.bare=false
core.logallrefupdates=true
remote.origin.url=ssh://git@10.25.115.212:7999/evd/arashtest.git
remote.origin.fetch=+refs/heads/*:refs/remotes/origin/*
branch.master.remote=origin
branch.master.merge=refs/heads/master
root@myvg:/repo# cat .git/config
[core]
        repositoryformatversion = 0
        filemode = true
        bare = false
        logallrefupdates = true
[remote "origin"]
        url = ssh://git@10.25.115.212:7999/evd/arashtest.git
        fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
        remote = origin
        merge = refs/heads/master
root@myvg:/repo#

If, from within /repo on my collector I try to perform a git checkout <X> where <X> is the branch the controller automatically created, I get the following error:

root@myvg:/repo# git checkout vg_6dfa167_Veri_Green
error: pathspec 'vg_6dfa167_Veri_Green' did not match any file(s) known to git.
root@myvg:/repo#

However the same command runs just fine after I perform a git fetch:

root@myvg:/repo# git fetch
remote: warning: unable to access '/root/.config/git/attributes': Permission denied
remote: Counting objects: 3, done.
remote: Compressing objects: 100% (3/3), done.
remote: Total 3 (delta 1), reused 0 (delta 0)
Unpacking objects: 100% (3/3), done.
From ssh://10.25.115.212:7999/evd/arashtest
 * [new branch]      vg_6dfa167_Veri_Green -> origin/vg_6dfa167_Veri_Green
 * [new branch]      vg_864f112_Veri_Green -> origin/vg_864f112_Veri_Green
root@myvg:/repo# git checkout vg_6dfa167_Veri_Green
Branch vg_6dfa167_Veri_Green set up to track remote branch vg_6dfa167_Veri_Green from origin.
Switched to a new branch 'vg_6dfa167_Veri_Green'
root@myvg:/repo# git status
On branch vg_6dfa167_Veri_Green
Your branch is up-to-date with 'origin/vg_6dfa167_Veri_Green'.
nothing to commit, working directory clean
root@myvg:/repo#

What am I missing here? Any help is greatly appreciated.

soninob commented 8 years ago

Please check in the config properties file, the location for the git repo is incorrect, should end with /example/path/.git Try to add /.git to your path. Let me know if its help.

persiarash commented 8 years ago

Hi @soninob, thanks for the help. Adding .git did resolve my issue, but only after I made sure to move my repo to /repo on my docker HOST. Otherwise I'd get an error when trying to start up the collector that my paths don't match the VG_REPO environment variable (which I don't set, nor can I find a reference to in the repository code).

Now the jenkins job isn't starting correctly, but that's another problem :)

Thanks again!

soninob commented 8 years ago

closing this one.