Hi,
I was wondering if there's a list / description somewhere of the environmental variables that are available to hooks?
Specifically, I'm wondering if there is anything that could be used to derive the path for cloning (http/ssh)?
thanks,
Garret
Hi Garret,
I think I might need to ask what you need to achieve with this hook and clone URLs before I can answer this properly.
Are you talking about hooks post Stash 2.0? I ask because prior to that hooks in Stash were invoked mostly without much environmental context. As part of providing branch permissions in 2.0 we have decided to install custom hooks to talk-back to Stash. In future versions of Stash the process of adding in-app hooks will be better documented and fully-supported.
If you're interested in post-receive hook specifically, and don't need to be synchronous or return input to the user, then I would recommend writing a plugin that listens for the RepositoryPushEvent. In 2.0 this even has a list of RefChanges. Otherwise you _could_ attempt to use our undocumented api for PostReceiveHook.
Either way, if you're in Java, you can use NavBuilder.clone() to find the correct HTTP URL.
I hope this helps.
Cheers,
Charles
Hi Charles,
I am evaluating Stash 2.0 and I'm anxious to see improved hook management in future versions of Stash.
Specifically, what I want to do is add a simple shell (no java) script to trigger our build system based on Jenkins. This is described here:
https://wiki.jenkins-ci.org/display/JENKINS/Git+Plugin#GitPlugin-Pushnotificationfromrepository
I have this working as advertised, but the
<URL of the Git repository>
is hard coded. It would be much easier to maintain if I could use an environmental variable here and then share the common hook across all of our repsoitories.
thanks,
Garret
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Garret,
Regarding hooks, we are trying to improve the whole hook experience in the next release. That said I do think that focus will be on the Java side of things.
I'm afraid there isn't likely to be an easy way to do this via scripts now or in future releases. If I get a spare second today I might try and send you an example Java project that will do the trick - it really will be the best/easiest way to achieve what you want.
Cheers,
Charles
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Charles,
That would be great to have an example. I imagine that others would find it useful as well.
thanks,
Garret
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Garret,
I've just whipped a hard-coded plugin, with no pretty UI at the moment. I'm hoping it's enough to get you started. You'll need to clone that repository, build via maven (which can be found in the Atlassian plugin SDK) and upload to your Stash instance.
https://bitbucket.org/atlassian/stash-webhook-plugin
Is that what you had in mind? Let me know if you have any problems.
Cheers,
Charles
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
FYI For anyone looking for that example I've migrated it to our Atlassian account:
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
hi Charles,
I am also in need for a post receive hook. I am using stash 2.0.2 now. I am not a java developer.
1) the link you provided is broken.
2) I don't understand how to write a hook now, since I am not a java developer,as I said. in basic git, what stash is suppose to manage or extened, rather than limit, you could write a script which will do what you need and put it under the hooks directory, and that was it.
how can you say "improve the whole hook experience" while you took out a very basic functionality of Git ??
now I need to learn java, use maven, etc etc... why ?? all I wanted was to write a simple hook. why not adding this option to stash rather than killing it all together ?
am I missing something here ?
Gabby.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Gabby,
Charles has moved the example to the Atlassian account (see his comment above). The new url is https://bitbucket.org/atlassian/stash-webhook-plugin.
With respect to needing to learn Java, Maven and more.. Stash supports Java plugins in addition to standard git hooks. If you want to write a hook using bash, perl, or your favourite (scripting) language, you can simply drop your script in the <STASH_HOME>/data/repositories/<repository-id>/hooks/pre-receive.d directory.
Stash makes the REMOTE_USER environment variables available to your script so you can tell which user pushed to Stash.
Cheers,
Michael
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Gabby,
Sorry about the broken link - I don't know how that happened. I've updated it now.
Technically we haven't taken out anything of Git. On the Stash server there are still normally Git repository which you are more than welcome to modify if that suits your needs. We haven't killed anything. The downside of this approach is that it can _only_ be done by the system administrator by updating the filesystem and is difficult to customise based on per-repository settings (for example).
Building hooks in Java is really a way for us to harness the power of the Altassian plugin ecosystem. Using our hook APIs plugin developers will be able to enhance Stash in various ways that just aren't possible with a script. For example when someone pushes a commit to Stash we could update the related JIRA issue, using the configured application links, as well as notifying Bamboo. Sure, you possibly do that in a script, but then how would you share that with other Stash users via our marketplace?
I hope this answers your question.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks Michael and Charles,
That is what I was expecting. I couldn’t figure that out from thread. I was under the impression that the hooks mechanism has changed in a way that it will be much more difficult to handle.
thanks a lot.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
As far as I can tell, and it might be staring me in the face, I can't seem to edit a comment, only an "answer". Annoying. Just in case you didn't see the link:
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.