mohamicorp / stash-jenkins-postreceive-webhook

Webhook used to notify Jenkins when commits are made to Stash
Other
138 stars 98 forks source link

build notifications are broken for pull request operations #133

Open anandsterlite opened 9 years ago

anandsterlite commented 9 years ago

When we submit a pull request or reopen or update, this plugin couldn't able to resolve 'SSH clone url' using Stash SPIs, so the build notifications to jenkins are failing around this functionality.

"POST /rest/api/latest/projects/PROJECT/repos/REPOSITORY/pull-requests/3/reopen HTTP/1.1" com.nerdwin15.stash.webhook.Notifier Error getting Jenkins URL java.lang.IllegalStateException: There were no SSH clone links generated for repository PROJECT/REPOSITORY at com.atlassian.stash.internal.ssh.service.DefaultSshCloneUrlResolver.getCloneUrl(DefaultSshCloneUrlResolver.java:37) ~[na:na] at com.nerdwin15.stash.webhook.Notifier$2.perform(Notifier.java:258) ~[plugin.2984264582819201899.stash-webhook-jenkins-2.7.0_1437075501000.jar:na] at com.nerdwin15.stash.webhook.Notifier$2.perform(Notifier.java:255) ~[plugin.2984264582819201899.stash-webhook-jenkins-2.7.0_1437075501000.jar:na] at com.atlassian.stash.internal.user.DefaultEscalatedSecurityContext.call(DefaultEscalatedSecurityContext.java:51) ~[stash-service-impl-3.11.0.jar:na] at com.atlassian.stash.internal.user.DefaultSecurityService.doWithPermission(DefaultSecurityService.java:77) ~[stash-service-impl-3.11.0.jar:na] at com.nerdwin15.stash.webhook.Notifier.getUrl(Notifier.java:255) [plugin.2984264582819201899.stash-webhook-jenkins-2.7.0_1437075501000.jar:na] at com.nerdwin15.stash.webhook.Notifier.notify(Notifier.java:196) [plugin.2984264582819201899.stash-webhook-jenkins-2.7.0_1437075501000.jar:na] at com.nerdwin15.stash.webhook.Notifier.notify(Notifier.java:165) [plugin.2984264582819201899.stash-webhook-jenkins-2.7.0_1437075501000.jar:na] at com.nerdwin15.stash.webhook.Notifier$1.call(Notifier.java:144) [plugin.2984264582819201899.stash-webhook-jenkins-2.7.0_1437075501000.jar:na] at com.nerdwin15.stash.webhook.Notifier$1.call(Notifier.java:141) [plugin.2984264582819201899.stash-webhook-jenkins-2.7.0_1437075501000.jar:na] at java.util.concurrent.FutureTask.run(FutureTask.java:262) [na:1.7.0_75] at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) [na:1.7.0_75] at java.lang.Thread.run(Thread.java:745) [na:1.7.0_75] ... 44 frames trimmed

pdodds commented 9 years ago

I believe this problem is due to the fact that you have requested an SSH clone but you don't have any SSH keys on your account?

mikesir87 commented 9 years ago

@anandsterlite - any answer to the question from @pdodds? Obviously, it probably shouldn't be blowing up if there aren't SSH keys/clone URLs, but want to make sure that's the case first.

jweisner commented 9 years ago

I'm having the same issue, and getting the same error output in atlassian-stash.log

Stash 3.11.1, my account definitely has an SSH key defined.

This is only occurring on new repositories that I create. I have around 200 older repos that I created, they still notify Jenkins without any problem. Some users seem to be able to create repos with the same settings, and the Jenkins hook works on those repos, even for my account.

mikesir87 commented 9 years ago

So, seems that this problem is occurring for more folks, but having trouble trying to figure out the common thread in the problems. Couple of quick questions... does it seem to cause any difference on the user that created the repo or the user that pushed the commits? Wonder if there might be some admin rights issue.

jweisner commented 9 years ago

I thought I had it nailed down to something with repos that I created, but that theory didn't pan out this morning when I had someone else create a new repo... the same person whose new repo last worked for me. Both of us have always used non-admin accounts to keep from seeing code outside of our department.

I created a repo with the "admin" account, no difference there either. The old repos continue to work no matter who pushes the changes. Everyone gets the same error in Stash's log when they push code to the new repos. Everything was working fine before we upgraded Stash from 3.6.1 to 3.11.1.

Sorry about the ramble, but I'm kind of stumped. Please let me know what I can provide for debugging data and testing.

jweisner commented 9 years ago

I just installed a fresh demo copy of Stash 3.11.1 with no other plugins enabled, everything "stock", only the admin account, only one repo, and this error was triggered.

This is on CentOS 6.6 (x86_64) fully patched.

I think it's probably something with Stash 3.11.1.

snoopotic commented 9 years ago

Stash now Requires Java 8. The Reporter uses 7. please Update breite further Investigation Males sense.

snoopotic commented 9 years ago

breite = before; Males = makes. Damn autocorrect on phone. Sorry.

jweisner commented 9 years ago

Stash is using the bundled JRE, and there is no other JRE installed on the server:

[root@stashtest ~]# which java
/usr/bin/which: no java in (/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin)
[root@stashtest ~]# /opt/atlassian/stash/3.11.1/jre/bin/java -version
java version "1.8.0_40"
Java(TM) SE Runtime Environment (build 1.8.0_40-b25)
Java HotSpot(TM) 64-Bit Server VM (build 25.40-b25, mixed mode)

The only modification made to the setenv.sh was to add http proxy params to JVM_SUPPORT_RECOMMENDED_ARGS. I accepted all defaults during the install.

mikesir87 commented 9 years ago

With the fresh Stash install, did you setup SSH access for cloning? Can't remember if that's turned on by default now or not.

jweisner commented 9 years ago

SSH functionality is enabled by default: screen shot 2015-08-07 at 10 18 55 am

I used HTTP for the initial git clone because I didn't add an SSH key to the admin account (keeping the changes to a minimum for troubleshooting).

I have added an SSH public key to the admin account, cloned the repo, added a simple text file, and pushed the change back to stashtest:

2015-08-07 10:16:11,184 INFO  [http-nio-7990-exec-10] admin @1OH3QE1x616x272x0 t8pu0h 10.0.96.250 "GET /plugins/servlet/ssh/account/keys HTTP/1.1" c.a.s.i.s.s.DefaultHostKeyPairProvider Generating host key...
2015-08-07 10:17:33,124 ERROR [JenkinsWebhook:thread-2] @1OH3QE1x617x315x0 19yr5dw 10.0.96.250 SSH - git-receive-pack '/tes/myrepo.git' com.nerdwin15.stash.webhook.Notifier Error getting Jenkins URL
java.lang.IllegalStateException: There were no SSH clone links generated for repository TES/myrepo
        at com.atlassian.stash.internal.ssh.service.DefaultSshCloneUrlResolver.getCloneUrl(DefaultSshCloneUrlResolver.java:37) ~[na:na]
        at com.nerdwin15.stash.webhook.Notifier$2.perform(Notifier.java:258) ~[plugin.2767623068843042034.stash-webhook-jenkins-2.7.0_1438924776000.jar:na]
        at com.nerdwin15.stash.webhook.Notifier$2.perform(Notifier.java:255) ~[plugin.2767623068843042034.stash-webhook-jenkins-2.7.0_1438924776000.jar:na]
        at com.atlassian.stash.internal.user.DefaultEscalatedSecurityContext.call(DefaultEscalatedSecurityContext.java:51) ~[stash-service-impl-3.11.1.jar:na]
        at com.atlassian.stash.internal.user.DefaultSecurityService.doWithPermission(DefaultSecurityService.java:77) ~[stash-service-impl-3.11.1.jar:na]
        at com.nerdwin15.stash.webhook.Notifier.getUrl(Notifier.java:255) [plugin.2767623068843042034.stash-webhook-jenkins-2.7.0_1438924776000.jar:na]
        at com.nerdwin15.stash.webhook.Notifier.notify(Notifier.java:196) [plugin.2767623068843042034.stash-webhook-jenkins-2.7.0_1438924776000.jar:na]
        at com.nerdwin15.stash.webhook.Notifier.notify(Notifier.java:165) [plugin.2767623068843042034.stash-webhook-jenkins-2.7.0_1438924776000.jar:na]
        at com.nerdwin15.stash.webhook.Notifier$1.call(Notifier.java:144) [plugin.2767623068843042034.stash-webhook-jenkins-2.7.0_1438924776000.jar:na]
        at com.nerdwin15.stash.webhook.Notifier$1.call(Notifier.java:141) [plugin.2767623068843042034.stash-webhook-jenkins-2.7.0_1438924776000.jar:na]
        at java.util.concurrent.FutureTask.run(FutureTask.java:266) [na:1.8.0_40]
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [na:1.8.0_40]
        at java.lang.Thread.run(Thread.java:745) [na:1.8.0_40]
        ... 44 frames trimmed
mikesir87 commented 9 years ago

Mk. Might have to do some source code digging into Stash. Not sure why this might have all of a sudden changed.

@jweisner - You said you're seeing this in Stash 3.11.1. @anandsterlite - what version of Stash were you using?

Any other versions seeing this too?

jweisner commented 9 years ago

The only thing remotely related that I could find in Atlassian's JIRA: https://jira.atlassian.com/browse/STASH-7656

TD-4242 commented 9 years ago

I get a the same error. My issue seems to be a duplicate of this and was closed. The only difference I can add is that when doing a test trigger to Jenkins using the ssh path it triggers a build. It's commits that aren't triggering builds and occasionally dumping the reported stack trace.

https://github.com/Nerdwin15/stash-jenkins-postreceive-webhook/issues/145

jweisner commented 9 years ago

@TD-4242 what version of Stash?

Test triggers work for me as well, although they error out in Jenkins because of another issue #134

TD-4242 commented 9 years ago

@mikesir87 I'm currently on 3.11.0 and seeing the same issue. I've had to reset all my jenkins jobs to polling.

pior commented 9 years ago

Also getting this error after a git push:

SSH - git-receive-pack '/hc/rest-client.git' com.nerdwin15.stash.webhook.Notifier Error getting Jenkins URL
java.lang.IllegalStateException: There were no SSH clone links generated for repository HC/rest-client

While the test trigger button works. Stash v3.11.1

pior commented 9 years ago

Could it be linked to this interface being deprecated?

https://developer.atlassian.com/static/javadoc/stash/3.11.1/ssh/reference/com/atlassian/stash/ssh/api/SshCloneUrlResolver.html

mikesir87 commented 9 years ago

It could be related, but it's actually been deprecated for a while. It won't be removed until Stash 4.0.

Will dig into the source code a little tonight and see what conditions might also play a factor.

On Wed, Aug 12, 2015, 3:18 PM Pior Bastida notifications@github.com wrote:

Could it be linked to this interface being deprecated?

https://developer.atlassian.com/static/javadoc/stash/3.11.1/ssh/reference/com/atlassian/stash/ssh/api/SshCloneUrlResolver.html

— Reply to this email directly or view it on GitHub https://github.com/Nerdwin15/stash-jenkins-postreceive-webhook/issues/133#issuecomment-130416580 .

pior commented 9 years ago

@mikesir87 I did a test: changed the "Repo Clone URL" from "SSH" to "CUSTOM" and specified the exact same (ssh) url. And it worked!

mikesir87 commented 9 years ago

@pior That would work because the link isn't being generated at notification time and you're specifying it. So, that's expected.

@TD-4242 @anandsterlite @jweisner - have either of you tried with Stash 3.11.2? I just tried it myself, fresh install, no setting changes. Looks likes the notification worked using SSH. Any luck on your end?

jweisner commented 9 years ago

I'm still seeing the java.lang.IllegalStateException: There were no SSH clone links generated for repository ... error on our existing production server after upgrading to 3.11.2.

Tried existing and new repos, no difference.

If this is now working in new installs, then perhaps the source of the problem is fixed, but there's an issue with Stash's stored configuration?

tohoku commented 9 years ago

@pior @mikesir87 I also had a related issue which was solved by changing the "Repo Clone URL" in the Webhook configuration modal from 'SSH' to 'Custom', but keeping the ssh:// address.

jenkins build console output:

 > git -c core.askpass=true fetch --tags --progress ssh://localhost:7999/test/testrepo.git +refs/heads/*:refs/remotes/origin/*
 > git rev-parse null^{commit} # timeout=10

FATAL: Command "git rev-parse null^{commit}" returned status code 128:
stdout: null^{commit}

stderr: fatal: ambiguous argument 'null^{commit}': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions, like this:
'git <command> [<revision>...] -- [<file>...]'

hudson.plugins.git.GitException: Command "git rev-parse null^{commit}" returned status code 128:
stdout: null^{commit}
TD-4242 commented 9 years ago

@mikesir87 I have not, currently we are set to Custom and it's working. It may be a while before I can swing back around and try the upgrade.

bmoyles commented 9 years ago

Ran into this after an upgrade to Stash 3.11.2. Odd thing is, it doesn't seem to be affecting all repos and I can't find a common thread between the broken ones (or obvious differences). If we set the clone URL to custom (but set it to the same as it would be for ssh), no problem.

vcmaxfield commented 9 years ago

Also ran into this after upgrade to 3.11.2.

However, if I try to set the Clone URL Type to Custom and use the same SSH URL, it reverts to SSH type upon save. If I change the URL a little bit, it stays on Custom.

bmoyles commented 9 years ago

We worked with Atlassian and they fixed the behavior in 3.11.4. We pushed out an update last week and so far looks good.

vcmaxfield commented 9 years ago

@bmoyles thanks for info!