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)?
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.
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:
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.
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.
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.
Is that what you had in mind? Let me know if you have any problems.
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 ?
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.
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.
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:
This community is celebrating its one-year anniversary and Atlassian co-founder Mike Cannon-Brookes has all the feels.Read more
Bitbucket Pipelines helps me manage and automate a number of serverless deployments to AWS Lambda and this is how I do it. I'm building Node.js Lambda functions using node-lambda ...
Connect with like-minded Atlassian users at free events near you!Find a group
Connect with like-minded Atlassian users at free events near you!
Unfortunately there are no AUG chapters near you at the moment.Start an AUG
You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs