Giter Club home page Giter Club logo

atlassian-external-hooks's People

Contributors

andreineculau avatar brian-kohler-heal avatar dploeger avatar georgy avatar gollub avatar kovetskiy avatar mmonsenhexagon avatar nickbroon avatar seletskiy avatar tuxmaster5000 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

atlassian-external-hooks's Issues

License?

Hi!

Thank you for the plugin, looks very promising. Please specify a license in your sources or provide a license file in your github repo. People might not use your plugin otherwise.

Best wishes

Florian

unpushed changes

the plugin shows up on the marketplace with latest version 3.0-1 (compatible with bitbucket server)
but not code has been pushed to this repo

Add compatibility with Bitbucket Server >= 5.0

Bitbucket Server 5.0 has deprecated the legacy hook API, quoting from the API Changelog:

New Hooks API

In Bitbucket Server 5.0 we are introducting a new API for Hooks. This API will replace the existing hooks API and the merge checks API. This new API makes retrieving added and removed commits much simpler and more efficient. For more information on the new API and how to use it, see the Repository Hooks and Merge Checks Guide.

The legacy Hooks API has been deprecated for removal in Bitbucket Server 6.0.

External merge check hook fires when pull request is created

I'm seeing the external merge check hook fire when the pull request is created and when it is merged. I wasn't expecting the external merge check hook to fire until the actual merge happens. Does anyone know if this is a bug or intended behavior?

If it's intended behavior, is there a way to distinguish between creating the pull request and merging the pull request?

Ultimately what I'm trying to do is run a cleanup script when a merge happens and the user marks the branch to be deleted. I'm using the latest version of Bitbucket Server with the latest version of the plugin.

As an example, here are the hashes and ref names for a simple sequence of events creating a commit on an new branch, creating a pull request, and then merging the pull request:

  1. First commit to branch (external pre-receive hook: old hash, new hash, ref):
    0000000000000000000000000000000000000000 0867166de6bd16eaade962a1e4f4628608db7b87 refs/heads/test-branch

  2. Create pull request (external merge check hook: old hash, new hash, ref):
    e86689163b8a06e658550e1bf6263335b8e815d9 0867166de6bd16eaade962a1e4f4628608db7b87 refs/heads/master

  3. Merge pull request (external merge check hook: old hash, new hash, ref):
    e86689163b8a06e658550e1bf6263335b8e815d9 0867166de6bd16eaade962a1e4f4628608db7b87 refs/heads/master

I would have only expected the merge hook to fire on steps 1 and 3, not on step 2.

add stash full user name

Please add stash user name:

    if (currentUser.getDisplayName() != null) {
        env.put("STASH_DISPLAY_NAME", currentUser.getDisplayName());
    } else {
        log.error("Can't get user full name. getDisplayName() call returns null");
    }

You should be Stash Administrator to edit this field

This was brought up before here: #6

I understand the security concerns. However, it's also painful to funnel configuration through administrators when you have an enormous amount of repos and many different users trying to configure them.

I think a safe way to deal with this would be to allow certain paths to be "blessed" by administrators. Administrators have access to the local disk, and can install "safe" scripts and add them to a list, or put them into a blessed directory or something along those lines. Is this a possible compromise?

HTML tags in messages

Hi,

I am using external hook with BitBucket 4.10 and exiting with not 0 status with error message in stdout but I have html tags in messages. I guess code should be changed to avoid usages html tags in veto() call. Please check attachments.

screenshot from 2016-10-06 19-09-03
screenshot from 2016-10-06 19-09-14

Thanks.

ExternalMergeCheck embeds html tags in merge check errors

Reproducible in atlassian-external-hooks@master with Bitbucket Server 4.9.1. See the screenshot below. Obviously, happens because of https://github.com/ngsru/atlassian-external-hooks/blob/master/src/main/java/com/ngs/stash/externalhooks/hook/ExternalMergeCheckHook.java#L143. I've tested the code on Bitbucket 4.3, and it behaved as expected. Looks like they changed merge check errors rendering at some point of time between 4.3 and 4.9. I will make a pull request and remove the tags from MergeCheckHook, unless you suggest a better solution.

screen shot 2016-09-26 at 14 36 24

Add commit-msg hook for Pull request merge

Please add support to be able to edit the commit message for a pull request merge event. I have a template I'd like to use which pre-pends some text to the commit message.

Broken pipe IOException

Since upgrading from stash to bitbucket server the post-receive hooks don't fire anymore.

This appears in the logfile:

2016-03-01 14:24:33,034 ERROR [AtlassianEvent::thread-1] user.name @1LE1CN3x864x111801x0 13411v6 192.168.17.209,127.0.0.1 "POST /rest/branch-utils/latest/projects/PN/repos/site/branches HTTP/1.1" c.n.s.e.hook.ExternalPreReceiveHook Error running [/bin/sh, /var/git/repos/pn-site/hooks/post-receive] in /var/bitbucket/data/shared/data/repositories/12
java.io.IOException: Broken pipe
        at java.io.FileOutputStream.writeBytes(Native Method) ~[na:1.8.0_72]
        at java.io.FileOutputStream.write(FileOutputStream.java:326) ~[na:1.8.0_72]
        at java.io.BufferedOutputStream.flushBuffer(BufferedOutputStream.java:82) ~[na:1.8.0_72]
        at java.io.BufferedOutputStream.flush(BufferedOutputStream.java:140) ~[na:1.8.0_72]
        at java.io.FilterOutputStream.close(FilterOutputStream.java:158) ~[na:1.8.0_72]
        at com.ngs.stash.externalhooks.hook.ExternalPreReceiveHook.onReceive(ExternalPreReceiveHook.java:133) ~[plugin.793156020221014809.external-hooks-3.0-1_1453796236000.jar:na]
        at com.ngs.stash.externalhooks.hook.ExternalAsyncPostReceiveHook.postReceive(ExternalAsyncPostReceiveHook.java:46) [plugin.793156020221014809.external-hooks-3.0-1_1453796236000.jar:na]
        at com.atlassian.stash.internal.hook.repository.AsyncPostReceiveRepositoryHookAdapter$1.visit(AsyncPostReceiveRepositoryHookAdapter.java:49) [bitbucket-service-impl-4.3.0.jar:na]
        at com.atlassian.stash.internal.hook.repository.AsyncPostReceiveRepositoryHookAdapter$1.visit(AsyncPostReceiveRepositoryHookAdapter.java:45) [bitbucket-service-impl-4.3.0.jar:na]
        at com.atlassian.stash.internal.hook.repository.DefaultRepositoryHookService$RepositoryHookPagedTransactionCallback.doInTransaction(DefaultRepositoryHookService.java:574) [bitbucket-service-impl-4.3.0.jar:na]
        at com.atlassian.stash.internal.hook.repository.DefaultRepositoryHookService$RepositoryHookPagedTransactionCallback.doInTransaction(DefaultRepositoryHookService.java:550) [bitbucket-service-impl-4.3.0.jar:na]
        at org.springframework.transaction.support.TransactionTemplate.execute(TransactionTemplate.java:133) [spring-tx-4.2.2.RELEASE.jar:na]
        at com.atlassian.stash.internal.hook.repository.DefaultRepositoryHookService.visitEnabledHooks(DefaultRepositoryHookService.java:280) [bitbucket-service-impl-4.3.0.jar:na]
        at com.atlassian.stash.internal.hook.repository.AsyncPostReceiveRepositoryHookAdapter.postReceive(AsyncPostReceiveRepositoryHookAdapter.java:45) [bitbucket-service-impl-4.3.0.jar:na]
        at com.atlassian.stash.internal.hook.repository.AsyncPostReceiveRepositoryHookAdapter.onRefsChangedEvent(AsyncPostReceiveRepositoryHookAdapter.java:40) [bitbucket-service-impl-4.3.0.jar:na]
        at com.atlassian.event.internal.SingleParameterMethodListenerInvoker.invoke(SingleParameterMethodListenerInvoker.java:36) [atlassian-event-3.0.0.jar:na]
        at com.atlassian.stash.internal.event.AsyncBatchingInvokersTransformer$AsyncInvokerBatch.invoke(AsyncBatchingInvokersTransformer.java:94) [bitbucket-platform-4.3.0.jar:na]
        at com.atlassian.event.internal.AsynchronousAbleEventDispatcher$1$1.run(AsynchronousAbleEventDispatcher.java:46) [atlassian-event-3.0.0.jar:na]
        at com.atlassian.sal.core.executor.ThreadLocalDelegateRunnable.run(ThreadLocalDelegateRunnable.java:34) [sal-core-3.0.5.jar:na]
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [na:1.8.0_72]
        at java.lang.Thread.run(Thread.java:745) [na:1.8.0_72]
        ... 29 frames trimmed

On the shell, switching to the bitbucket user and going to the /var/bitbucket/data/shared/data/repositories/12 directory and running /bin/sh /var/git/repos/pn-site/hooks/post-receive FOO BAR BAZ works fine.

Any suggestions?

Not running on merge?

The astlassian developer documentation states that "Post-receive hooks are invoked after a push or merge has taken place" but my external hook is only called on pushes, not when merging pull-requests on stash.

Someone else has run into the same issue:
https://answers.atlassian.com/questions/287561/stash-plugin-for-that-triggers-a-remote-script-when-the-pull-request-is-merged
And he has posted sample code that should not have the issue.

However, I fail to understand why his code should work on merges and the code of external-hooks would not?

With windows server ?

Hi,

I'm using a stash v3.9.2 deployed on a windows 8.1 computer.
I've successfully install this add on, and configured it with mirror sample
The script seem to be executed regarding audit log when i push new commit.
If i try the script using git bash, it is well exectuted.
But there is no result when stash execute it.
Any idea ? Has someone already test the add'on under windows instance ?

Output for post-receive hook

Hi there!

  1. In wiki it says that post-receive hook output is silently ignored, but can this be enabled? No examples found.
  2. Can post-receive hook to get also stdin? In ideal situation i would like to make this post-receive hook interactive and provide some possible project deployment options.

Is it possible?

Thanks!

more env variables

Maybe it's me, but

  • the project name (e.g. STASH_PROJECT_NAME)
  • the base url (e.g. STASH_BASE_URL from com.atlassian.stash.server.getBaseUrl() ~ http(s)://stash.example.com)
  • the git url (e.g. STASH_GIT_URL ~ [email protected]: or http(s)://stash.example.com/scm/)

would also have their place as env variables, just like STASH_REPO_NAME

RejectedExecutionException with externalhooks flooding the event queue

I'm getting the RejectedExecutionException issue on my Bitbucket Server instance, and following the instructions on that ticket, I've identified External Hooks as the likely culprit.

When the event queue gets full, the stack traces for the event queue threads are all from external hooks, like this one:

2017-03-16 00:02:39,897 WARN  [http-nio-7990-exec-3] @1XK1CD1x2x329362x0 10.3.0.61,127.0.0.1 "GET /rest/api/1.0/projects/RR/repos/core/
pull-requests/1283/merge HTTP/1.0" c.a.s.i.e.EventThreadPoolExecutor Stack trace for AtlassianEvent::thread-2
com.atlassian.stash.internal.util.StackException: Stack trace for AtlassianEvent::thread-2
        at java.lang.Object.wait(Native Method) ~[na:1.8.0_45]
        at java.lang.Object.wait(Object.java:502) ~[na:1.8.0_45]
        at java.lang.UNIXProcess.waitFor(UNIXProcess.java:396) ~[na:1.8.0_45]
        at com.ngs.stash.externalhooks.hook.ExternalPreReceiveHook.runExternalHooks(ExternalPreReceiveHook.java:195) ~[na:na]
        at com.ngs.stash.externalhooks.hook.ExternalPreReceiveHook.onReceive(ExternalPreReceiveHook.java:67) ~[na:na]
        at com.ngs.stash.externalhooks.hook.ExternalAsyncPostReceiveHook.postReceive(ExternalAsyncPostReceiveHook.java:46) ~[na:na]
        at com.atlassian.stash.internal.hook.repository.AsyncPostReceiveRepositoryHookAdapter$1.visit(AsyncPostReceiveRepositoryHookAda
pter.java:49) ~[bitbucket-service-impl-4.13.0.jar:na]
        at com.atlassian.stash.internal.hook.repository.AsyncPostReceiveRepositoryHookAdapter$1.visit(AsyncPostReceiveRepositoryHookAda
pter.java:45) ~[bitbucket-service-impl-4.13.0.jar:na]
        at com.atlassian.stash.internal.hook.repository.DefaultRepositoryHookService$RepositoryHookPagedTransactionCallback.doInTransac
tion(DefaultRepositoryHookService.java:573) ~[bitbucket-service-impl-4.13.0.jar:na]
        at com.atlassian.stash.internal.hook.repository.DefaultRepositoryHookService$RepositoryHookPagedTransactionCallback.doInTransac
tion(DefaultRepositoryHookService.java:549) ~[bitbucket-service-impl-4.13.0.jar:na]
        at org.springframework.transaction.support.TransactionTemplate.execute(TransactionTemplate.java:133) ~[spring-tx-4.3.4.RELEASE.
jar:4.3.4.RELEASE]
        at com.atlassian.stash.internal.hook.repository.DefaultRepositoryHookService.visitEnabledHooks(DefaultRepositoryHookService.jav
a:279) ~[bitbucket-service-impl-4.13.0.jar:na]
        at com.atlassian.stash.internal.hook.repository.AsyncPostReceiveRepositoryHookAdapter.postReceive(AsyncPostReceiveRepositoryHoo
kAdapter.java:45) ~[bitbucket-service-impl-4.13.0.jar:na]
        at com.atlassian.stash.internal.hook.repository.AsyncPostReceiveRepositoryHookAdapter.onRefsChangedEvent(AsyncPostReceiveReposi
toryHookAdapter.java:40) ~[bitbucket-service-impl-4.13.0.jar:na]
        at com.atlassian.event.internal.SingleParameterMethodListenerInvoker.invoke(SingleParameterMethodListenerInvoker.java:40) ~[atl
assian-event-3.1.3.jar:na]
        at com.atlassian.stash.internal.event.AsyncBatchingInvokersTransformer$AsyncInvokerBatch.invoke(AsyncBatchingInvokersTransforme
r.java:109) ~[bitbucket-platform-4.13.0.jar:na]
        at com.atlassian.event.internal.AsynchronousAbleEventDispatcher$1$1.run(AsynchronousAbleEventDispatcher.java:38) ~[atlassian-ev
ent-3.1.3.jar:na]
        at com.atlassian.sal.core.executor.ThreadLocalDelegateRunnable.run(ThreadLocalDelegateRunnable.java:34) ~[sal-core-3.0.6.jar:na
]
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) ~[na:1.8.0_45]
        at java.lang.Thread.run(Thread.java:745) [na:1.8.0_45]
        ... 29 frames trimmed

That seems to indicate External Hooks is using the event thread to perform the work, instead of queueing it for execution out of its own thread pool.

how to verify commit message during push ?

I have a commit-msg hook that works fine when used with a 'raw' git repo and I'm trying to use your plugin to use it in a Stash git repo, so commit message are verified whenever anything is pushed to the repo.

I can't seem to figure out what positional parameters I need to specify in order to pass the commit message to the script.

Can you help me ?

Configure via API

Would love to be able to set a hook using the bitbucket REST API endpoint. Any chance you can hook into this?

ExternalPreReceiveHook.onReceive calls PermissionService.hasAnyUserPermission with global permissions

https://github.com/ngsru/atlassian-external-hooks/blob/master/src/main/java/com/ngs/stash/externalhooks/hook/ExternalPreReceiveHook.java#L52

calls PermissionService.hasAnyUserPermission with SYSADMIN and ADMIN. The contract on hasAnyUserPermission only allows resource permissions to be queried (PROJECT_* or REPO_*). If you provide a global permission, an IllegalArgumentException is thrown.

The whole check can be collapsed into a single call permissions.hasRepositoryPermission(currentUser, repo, Permission.REPO_ADMIN) because PROJECT_ADMIN, ADMIN and SYSADMIN all imply REPO_ADMIN

Compatibility with Stash 3.2.0

After upgrading to Stash 3.2.0, my post-receive hooks stopped working. It looks like it is related to the reorganization the Stash home directory.

From the atlassian-stash.log file, I found this:

java.io.IOException: Cannot run program "/var/atlassian/application-data/stash/stash_slack.sh" (in directory "/var/atlassian/application-data/stash/data/repositories/27"): error=2, No such file or directory
t java.lang.ProcessBuilder.start(ProcessBuilder.java:1047) ~[na:1.7.0_65]
    at com.ngs.stash.externalhooks.hook.ExternalPreReceiveHook.onReceive(ExternalPreReceiveHook.java:59) ~[plugin.6579998661888744121.external-hooks-1.3-8_1401424832000.jar:na]
    at com.ngs.stash.externalhooks.hook.ExternalPostReceiveHook.postReceive(ExternalPostReceiveHook.java:36) [plugin.6579998661888744121.external-hooks-1.3-8_1401424832000.jar:na]
    at com.atlassian.stash.internal.hook.repository.AsyncPostReceiveRepositoryHookAdapter$1.visit(AsyncPostReceiveRepositoryHookAdapter.java:49) [stash-service-impl-3.2.0.jar:na]
    at com.atlassian.stash.internal.hook.repository.AsyncPostReceiveRepositoryHookAdapter$1.visit(AsyncPostReceiveRepositoryHookAdapter.java:45) [stash-service-impl-3.2.0.jar:na]
    at com.atlassian.stash.internal.hook.repository.DefaultRepositoryHookService$RepositoryHookPagedTransactionCallback.doInTransaction(DefaultRepositoryHookService.java:616) [stash-service-impl-3.2.0.jar:na]
    at com.atlassian.stash.internal.hook.repository.DefaultRepositoryHookService$RepositoryHookPagedTransactionCallback.doInTransaction(DefaultRepositoryHookService.java:592) [stash-service-impl-3.2.0.jar:na]
    at org.springframework.transaction.support.TransactionTemplate.execute(TransactionTemplate.java:133) [spring-tx-4.0.5.RELEASE.jar:4.0.5.RELEASE]
    at com.atlassian.stash.internal.hook.repository.DefaultRepositoryHookService.visitEnabledHooks(DefaultRepositoryHookService.java:304) [stash-service-impl-3.2.0.jar:na]
    at com.atlassian.stash.internal.hook.repository.AsyncPostReceiveRepositoryHookAdapter.postReceive(AsyncPostReceiveRepositoryHookAdapter.java:45) [stash-service-impl-3.2.0.jar:na]
    at com.atlassian.stash.internal.hook.repository.AsyncPostReceiveRepositoryHookAdapter.onRefsChangedEvent(AsyncPostReceiveRepositoryHookAdapter.java:40) [stash-service-impl-3.2.0.jar:na]
    at com.atlassian.event.internal.SingleParameterMethodListenerInvoker.invoke(SingleParameterMethodListenerInvoker.java:36) [atlassian-event-2.3.5.jar:na]
    at com.atlassian.stash.internal.event.AsyncBatchingInvokersTransformer$AsyncInvokerBatch.invoke(AsyncBatchingInvokersTransformer.java:100) [stash-platform-3.2.0.jar:na]
    at com.atlassian.event.internal.AsynchronousAbleEventDispatcher$1$1.run(AsynchronousAbleEventDispatcher.java:48) [atlassian-event-2.3.5.jar:na]
    at com.atlassian.sal.core.executor.ThreadLocalDelegateRunnable.run(ThreadLocalDelegateRunnable.java:38) [sal-core-2.12.1.jar:na]
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) [na:1.7.0_65]
    at java.lang.Thread.run(Thread.java:745) [na:1.7.0_65]
    ... 31 frames trimmed
Caused by: java.io.IOException: error=2, No such file or directory
    at java.lang.UNIXProcess.forkAndExec(Native Method) ~[na:1.7.0_65]
    at java.lang.UNIXProcess.<init>(UNIXProcess.java:186) ~[na:1.7.0_65]
    at java.lang.ProcessImpl.start(ProcessImpl.java:130) ~[na:1.7.0_65]
    at java.lang.ProcessBuilder.start(ProcessBuilder.java:1028) ~[na:1.7.0_65]
    ... 17 common frames omitted

The directory /var/atlassian/application-data/stash/data no longer exists under Stash 3.2.0. It seems to have moved to /var/atlassian/application-data/stash/shared/data.

Specified path is not executable file. Check executable flag.

I have a file at the following path: /external-hooks/test/checkpep8.sh

I put it in the "Executable:" field as "/test/checkpep8.sh" but I keep getting the error message that "Specified path is not executable file. Check executable flag."

I have Safe Mode enabled. I am logged in as the repo admin. I've also tried "./test/checkpep8.sh", "checkpep8.sh", and many other variants. I have also entered into the command line "chmod u+x checkpep8.sh" to make sure that the file is executable, but I still keep getting the error message that it is not executable.

What is wrong with the file I specified?

hook plugin returns null

I am using stash 3.6.1 and have a shell script to be triggered as a pre-receive hook via the external hook plugin.
I am getting this message and the push is failing:
Writing objects: 100% (8/8), 670 bytes | 0 bytes/s, done.
Total 8 (delta 6), reused 0 (delta 0)
remote: Hook com.ngs.stash.externalhooks.hook.ExternalPreReceiveHook failed. Error:
remote: null
To ssh://git@:7999/hpln/backend.git
! [remote rejected] BudIceEverGreen -> BudIceEverGreen (pre-receive hook declined)
error: failed to push some refs to 'ssh://git@

from the log we can see there is an exception being thrown:

2015-02-11 19:17:45,652 WARN [threadpool:thread-5] Access key user (romanog@ROMANOG9) @1QZZ33Kx1157x519x0 95s4cq 16.60.202.173 SSH - gi
t-receive-pack '/hpln/backend.git' c.a.s.i.h.r.PreReceiveRepositoryHookAdapter Receive Hook com.ngs.stash.externalhooks.hook.ExternalPre
ReceiveHook failed.
java.lang.NullPointerException: null
at java.lang.ProcessEnvironment.validateValue(ProcessEnvironment.java:119) ~[na:1.7.0_65]
at java.lang.ProcessEnvironment.access$400(ProcessEnvironment.java:61) ~[na:1.7.0_65]
at java.lang.ProcessEnvironment$Value.valueOf(ProcessEnvironment.java:202) ~[na:1.7.0_65]
at java.lang.ProcessEnvironment$StringEnvironment.put(ProcessEnvironment.java:241) ~[na:1.7.0_65]
at java.lang.ProcessEnvironment$StringEnvironment.put(ProcessEnvironment.java:220) ~[na:1.7.0_65]
at com.ngs.stash.externalhooks.hook.ExternalPreReceiveHook.onReceive(ExternalPreReceiveHook.java:81) ~[na:na]
at com.atlassian.stash.internal.hook.repository.PreReceiveRepositoryHookAdapter$1.visit(PreReceiveRepositoryHookAdapter.java:38)
[stash-service-impl-3.6.1.jar:na]
at com.atlassian.stash.internal.hook.repository.PreReceiveRepositoryHookAdapter$1.visit(PreReceiveRepositoryHookAdapter.java:33)
[stash-service-impl-3.6.1.jar:na]
at com.atlassian.stash.internal.hook.repository.DefaultRepositoryHookService$RepositoryHookPagedTransactionCallback.doInTransact
ion(DefaultRepositoryHookService.java:616) [stash-service-impl-3.6.1.jar:na]
at com.atlassian.stash.internal.hook.repository.DefaultRepositoryHookService$RepositoryHookPagedTransactionCallback.doInTransact
ion(DefaultRepositoryHookService.java:592) [stash-service-impl-3.6.1.jar:na]
at org.springframework.transaction.support.TransactionTemplate.execute(TransactionTemplate.java:133) [spring-tx-4.1.1.RELEASE.ja
r:4.1.1.RELEASE]
at com.atlassian.stash.internal.hook.repository.DefaultRepositoryHookService.visitEnabledHooks(DefaultRepositoryHookService.java
:304) [stash-service-impl-3.6.1.jar:na]
at com.atlassian.stash.internal.plugin.OsgiSafeProxyProvider$1.invoke(OsgiSafeProxyProvider.java:93) [stash-platform-3.6.1.jar:na]
at com.atlassian.stash.internal.hook.repository.PreReceiveRepositoryHookAdapter.onReceive(PreReceiveRepositoryHookAdapter.java:3
3) [stash-service-impl-3.6.1.jar:na]
at com.atlassian.stash.internal.hook.DefaultBuiltInHookHandlerFactory$1.handle(DefaultBuiltInHookHandlerFactory.java:43) [stash-
service-impl-3.6.1.jar:na]
at com.atlassian.stash.internal.hook.DefaultHookService.doHandleRequest(DefaultHookService.java:341) [stash-service-impl-3.6.1.j
ar:na]
at com.atlassian.stash.internal.hook.DefaultHookService.handleRequest(DefaultHookService.java:327) [stash-service-impl-3.6.1.jar
:na]
at com.atlassian.stash.internal.hook.DefaultHookService.handleRawRequest(DefaultHookService.java:238) [stash-service-impl-3.6.1.
jar:na]
at com.atlassian.stash.internal.hook.DefaultHookService$2$1.run(DefaultHookService.java:204) [stash-service-impl-3.6.1.jar:na]
at com.atlassian.stash.internal.concurrent.StateTransferringExecutor$StateTransferringRunnable.run(StateTransferringExecutor.jav
a:69) [stash-platform-3.6.1.jar:na]
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471) [na:1.7.0_65]
at java.util.concurrent.FutureTask.run(FutureTask.java:262) [na:1.7.0_65]
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:178) [na:1.7
.0_65]
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:292) [na:1.7.0_65]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) [na:1.7.0_65]

External Pre Receive Hook not run when Creating a branch via the Bitbucket UI

Hj
We have a branching model where we want to ensure that our developers branches are namespaced i.e chris/ to enforce this we have written and External Pre Receive Hook that is run we when our developers try to push to bitbucket and the push is rejected if the do not confirm to our branching strategy.

This is working fine if one works via a shell and the hook works fine but for som reason when one creates a branch the Bitbucket UI the External Pre Receive Hook is not run and the branch creation is not rejected. Is there a way one can get External Pre Receive Hook also to run when creating the branch via the UI alternatively do you have any thoughts of an alternative solution to implement this?

We are using the 3.3-1 add-on of the external hooks and v4.14.3 of bitbucket

Regards
Chris

add tag after merge of pull request

I need an algorithm of how to add tag to merge commit of pull request. At the moment we use git commands in the script:
git tag -a "${SOFTWARE_VERSION}" -m "${DESCRIPTION}" ${TO_HASH_COMMIT}

Environment variables are correct and in fact I see new tags in root repository.

BUT: These new tags dont synchronized with forks. I already tried to talk with attlassian support but they dont support external tools and aren`t going to response any actions made through it.

There was a mind to add git push --tags to fix add command but this doesn`t work as well.

What is only works is direct clone of root repository - add tag - push it to origin. After such chain new tags really start syncing with forks.

Any ideas?

Feature Request: General Config option to disable non-safeDir

Would it be possible to add an option in the general plugin configuration settings to disable the ability to run scripts outside of the safeDir ($STASH_HOME/external-hooks/)? We give admin to a large subset of our users so they can add repos and manage permissions as needed, but we aren't comfortable with them being able to upload and run arbitrary CLI scripts on the server.

In other words, we could go to "Manage Add-Ons"->"External Hooks"->"Configure" and uncheck an option "Allows scripts outside safeDir" or similar.

Git push hangs with external Plugin

I have enabled external plugin in our environment with Bitbucket 4.6.1 and server load started to increase while there is push with this plugin enabled .

I have configured bash script to run as part of external pre hook ..

Please suggest how to fix this issue ... I am really interested with this plugin since I configure what ever I want to do via script ..

Branch name

Does this plugin pass in the branch name into the executable

Execute pre/post-receive hooks when editing files in the browser

I had to disable Bitbucket's online editing feature because it doesn't invoke our pre/post-receive hooks. However, the issue [BSERV-9521|https://jira.atlassian.com/browse/BSERV-9521] was closed suggesting that Bitbucket 5.0 implements a new hook API which also invokes hooks when a file is edited or created in the browser.

Would you consider this as an improvement? Without this I can't enable Bitbucket's online editing feature.

Thanks!

WIndows post recieve hook

Hi,

I am getting no joy setting this up in windows. I am trying to set up a hook to checkout files from a bare repo into a specific folder when I push to the repo so that I can produce a filesystem of branches for the webserver to use.

I am calling the file deploy.cmd which contains

cmd.exe /c ""C:\Program Files\Git\bin\sh.exe" --login -i -- "G:\programs\atlassian\home\bitbucket\external-hooks\deploy.sh"

and calls the actual hook containing:

!/bin/bash

echo "Starting copy from repository to work tree..."
pwd
hostname
git --work-tree=/g/appservers/webapps/$STASH_REPO_NAME/test/$STASH_PROJECT_NAME checkout -f

Nothing is happening and I have no idea where to start on this. I tried calling the .sh script directly but logs kept saying

Cannot run program "G:\programs\atlassian\home\bitbucket\external-hooks\deploy.sh" (in directory "G:\programs\atlassian\home\bitbucket\shared\data\repositories\51"): CreateProcess error=193, %1 is not a valid Win32 application

Do you have an example of how to do this on the windows platform? Also how do I get the branch name as a folder???

Update to work with git 2.11+

Possible duplicate of #49

See Atlassian notes here: https://jira.atlassian.com/browse/BSERV-9388

Our server recently updated git to 2.11, and pre-receive hooks started failing with "bad object" errors on new branches.

This extension needs to be updated to work with git's new handling of new objects with pre-receive hooks.

Edit:
It looks like the fix may be to pass some GIT_ environment variables to the pre-receive hook:

  • GIT_ALTERNATE_OBJECT_DIRECTORIES
  • GIT_OBJECT_DIRECTORY
  • GIT_QUARANTINE_PATH

Sources:

Is there any reason not to allow GIT_* variables to pass through to the hooks?

Must be Stash Admin to configure external hook

Hi, thanks for the hook. It's great. When I first started using it I could configure the hook as project Admin. Now, it will not let me configure the Executable and Positional Parameters of the External Post Receive Hook. It says, "You should be Stash Administrator to edit this field." Is that what you intended? It seems too restrictive to me.

Post-receive script with tag creation

I have a scritpt that creates a tag with an incrementing version number on each push to the master branch. It works fine when running standalone but does not work as external-hook script. I can see in the output that the tag has been created with the correct name but it does not show up in the bitbucket UI or when the repo is fetched. Any ideas on why?

#!/bin/bash

(
    while read from_ref to_ref ref_name; do
        branch=$(git rev-parse --symbolic --abbrev-ref $ref_name)
        if [ "master" = "$branch" ]; then
            GIT_DESCRIBE=`git describe --match=v[0-9]* 2>/dev/null`
            DASH_POS=`expr index "$GIT_DESCRIBE" -`
            LENGTH=`expr $DASH_POS - 2`
            NEW_VERSION=`expr ${GIT_DESCRIBE:1:$LENGTH} + 1`
            if [ "$NEW_VERSION" != "" ]; then
                git tag -a "v$NEW_VERSION" -m "v$NEW_VERSION"
                echo "Created a new tag, v$NEW_VERSION"
            fi
        fi
    done
) | tee -a /tmp/external-hooks-versiontag.log

post receive hook not firing

I'm running Stash 3.2.0 on a Windows server, and can't seem to get the post-receive external hook to fire. I've tried both version 2.0-1 and 1.3-9, and both fire the pre-receive hook but not the post-receive hook. The configuration for both hooks is the same in my test:
executable:

c:\Git\bin\bash.exe

positional params:

-c
pwd > /c/tmp/<file>.txt

where file is either 'pre-file' or 'post-file'.
When I push to the repository, pre-file.txt is created but post-file.txt is not.

Any suggestions what to try next?

Can't configure the plugin on a project level

Hi,

Is it a deliberate choice that the hook can not be configured on a project level? I've got a lot of repositories and having to configure on each separately is a bit of a hassle.

selection_947

Thanks

Commit hash passed to external hook script when braches created/merged is 000000000

During a merge into the master branch the parameters from the external hook plugin to the external bash script were: e5e98e5cb9f6c9dd4a12bb47de36c0283899236c 0000000000000000000000000000000000000000 refs/heads/user-dash

When a new branch was made locally, and committed, the parameters passed to the script were: 0000000000000000000000000000000000000000 f18cb17e1c0e31b52f5f8cd118e903e272f8af26 refs/heads/dashboards_dev

This caused trouble in the git log command used in the script (00... invalid commit).

Environment

Stash 3.2.0
External Hooks 2.0-1
CentOS 6.5
git 2.1.0-rc0

pre-receive hook on linux BitBucketServer: current commit is bad object

I have a pre-receive hook script patterned after the example hook in the documentation. We just switched from a Windows bitbucket server at version 4.3.0, where the pre-receive hook worked fine, to a linux bitbucket server at version 4.14.2, in which the pre-receive hook no longer works (but the post-receive hook works fine). In particular, this is the section of your example that I emulate in both pre- and post-receive hooks:
while read from_ref to_ref ref_name; do
echo "Ref update:"
echo " Old value: $from_ref"
echo " New value: $to_ref"
echo " Ref name: $ref_name"
echo " Diff:"
git show $from_ref..$to_ref | sed 's/^/ /'
done
The 'to_ref' is the commit ID of the last commit pushed; when the script is executed in the context of External Pre Receive Hook on linux, it's now generating a 'bad object' message when I try to use $to-ref as a git reference. The identical code executed in the context of the 'External Async Post Receive Hook' works fine on linux, and works fine in the External Pre Receive Hook on Windows.

I'd rather use the pre-receive hook if I could.

Thanks,
Tim Wendt

missing Save button when hook is disabled

at times, you test a hook, and then disable it.

but right now, you cannot remove the script path or its positional arguments because there is no Save button. Only an Enable button.

Save is only available when job is enabled.

"Can't get user email address" when receiving packets from "system accounts"

While monitoring our Bitbucket logs, we are facing a problem when the plugin tries to get the email adress of a "system account" that has only an access key to interact with Bitbucket:

/src/main/java/com/ngs/stash/externalhooks/hook/ExternalPreReceiveHook.java:

if (currentUser.getEmailAddress() != null) {
   env.put("STASH_USER_EMAIL", currentUser.getEmailAddress());
} else {
   log.error("Can't get user email address. getEmailAddress() call returns null");
}

OK, it cannot find an email adress as the committer is no real user with name/adress but is this really worth an error-loglevel? Is this STASH_USER_EMAIL information somewhere needed where it could be better logged as absent? By this logging, we got a log of false-positives.

Data center support

We were looking at using this addon to work on post hooks in bitbucket server. Is there a timeline to compile this code to support datacenter version of bitbucket ?

Which branch?

I am thinking about using this for auto deploy of projects, but I need these hooks for events when master branch is pushed or something is merged into branch...

I can not find if this is supported?

Thanks!

Never get more than one from-to line

When I push multiple commits in one push I'm always getting only the latest commit message and diff.
Reading the test script I would assume the while would return multiple lines, one per commit pushed.

Am I under a wrong assumption or is there some regression?

Setup: Stash 3.1.1, external-hooks 2.0-1

Test script output

Ref update:
 Old value: 2717c66303b3c8f29fdeb00ee26def7d7460aa73
 New value: b032adc546ade3c5be6d717c41e5bf2f51e094cc
 Ref name:  refs/heads/feature/DPDHLUP-123-Slack-integration
 Diff:
...

... where Ref update is always only once, never multiple times. My expectation was to see this once for each commit.

(p.s. thanks for the great hook :)

After adding an "External Async Post Receive Hook", any push LOOPS ENDLESSLY

Atlassian Bitbucket v4.14.4

From my own repos setting page:
/users/christopher.hahn/repos/hooktest/settings/hooks
this is the text from the hook config web-dialog:

External Async Post Receive Hook
Executable: basictest.sh
Path to executable to run.

Safe mode [X] Look for hooks only in safe dir
Hooks will be searched only in /external-hooks/

The script:
/var/atlassian/bitbucket-home/external-hooks/basictest.sh
is a classic, off the net:

#!/bin/bash
(
echo "Script name: $0"
echo "Positional arguments: ${@}"
echo "STASH_USER_NAME: $STASH_USER_NAME"
echo "STASH_USER_EMAIL: $STASH_USER_EMAIL"
echo "STASH_REPO_NAME: $STASH_REPO_NAME"
echo "STASH_IS_ADMIN: $STASH_IS_ADMIN"
while read from_ref to_ref ref_name; do
echo "Ref update:"
echo " Old value: $from_ref"
echo " New value: $to_ref"
echo " Ref name: $ref_name"
echo " Diff:"
git show $from_ref..$to_ref | sed 's/^/ /'
done
) | tee -a /tmp/external-hooks-test.log

The script is 755 and runs fine from the command line.
BUT, when I push any change, the console loops over the same output:

$ git push newbranch
Counting objects: 3, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 285 bytes | 0 bytes/s, done.
Total 3 (delta 1), reused 0 (delta 0)
remote:
remote: Create pull request for newbranch:
remote: https://XXXXX/users/christopher.hahn/repos/hooktest/compare/commits?sourceBranch=refs/head...
remote:
remote:
remote: Create pull request for newbranch:
remote: https://XXXXX/users/christopher.hahn/repos/hooktest/compare/commits?sourceBranch=refs/head...
remote:
remote:
remote: Create pull request for newbranch:
remote: https://XXXXX/users/christopher.hahn/repos/hooktest/compare/commits?sourceBranch=refs/head...

remote:
remote: Create pull request for newbranch:
remote: https://XXXXX/users/christopher.hahn/repos/hooktest/compare/commits?sourceBranch=refs/head...
remote:
Killed by signal 2.
fatal: The remote end hung up unexpectedly
error: error in sideband demultiplexer
To ssh://git@XXXXX:7999/~christopher.hahn/hooktest.git
35734f5..8544dec newbranch -> newbranch

Has anyone else seen this?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.