• Icon: Suggestion Suggestion
    • Resolution: Fixed
    • None
    • None
    • None
    • We collect Bitbucket feedback from various sources, and we evaluate what we've collected when planning our product roadmap. To understand how this piece of feedback will be reviewed, see our Implementation of New Features Policy.

      It would be useful for people writing custom git hooks to have access to the authenticated user in their hooks.

      Stash currently authenticates users when they push to or pull from a Stash repository, but does not pass on the user to git. We could easily make the user available through an environment variable (e.g. USER, STASH_USER or GIT_USER)

            [BSERV-2555] Make authenticated user available to git hooks

            Stefan, we are trying the same .. but seems like the build fails as soon as we add the constructor to the pre-hook plugin.
            I have opened a question with details In regards to the same as below .. hopefully you can guide us.
            https://answers.atlassian.com/questions/32968488/how-to-retrieve-logged-in-userid-in-pre-receive-hook-plugin
            -Thanks in advance

            Parvinder added a comment - Stefan, we are trying the same .. but seems like the build fails as soon as we add the constructor to the pre-hook plugin. I have opened a question with details In regards to the same as below .. hopefully you can guide us. https://answers.atlassian.com/questions/32968488/how-to-retrieve-logged-in-userid-in-pre-receive-hook-plugin -Thanks in advance

            Hi zaargy,

            It would be something along the lines of:

                // FooBar is the ctor
                public FooBar(StashAuthenticationContext authenticationContext) {
            

            and the following declaration in your atlassian-plugin.xml:

                <component-import key="stashAuthenticationContext" interface="com.atlassian.stash.user.StashAuthenticationContext" />
            

            In general, the best place to ask questions related to plugin development would be https://answers.atlassian.com/

            Cheers,
            Stefan

            Stefan Saasen (Inactive) added a comment - Hi zaargy , It would be something along the lines of: // FooBar is the ctor public FooBar(StashAuthenticationContext authenticationContext) { and the following declaration in your atlassian-plugin.xml : <component- import key= "stashAuthenticationContext" interface = "com.atlassian.stash.user.StashAuthenticationContext" /> In general, the best place to ask questions related to plugin development would be https://answers.atlassian.com/ Cheers, Stefan

            Hi,

            I am unable to work out how my repository hook is instantiated. What should the component constructor look like?

            Thanks,
            James

            James Gray added a comment - Hi, I am unable to work out how my repository hook is instantiated. What should the component constructor look like? Thanks, James

            mwatson added a comment -

            mwatson added a comment - No. Within a java hook, you should add the https://developer.atlassian.com/static/javadoc/stash/2.4.2/api/reference/com/atlassian/stash/user/StashAuthenticationContext.html to your plugin and component constructor and you'll be able to call the https://developer.atlassian.com/static/javadoc/stash/2.4.2/api/reference/com/atlassian/stash/user/StashAuthenticationContext.html#getCurrentUser( ) method. Matt

            James Gray added a comment -

            Hi,

            Is REMOTE_USER still applicable when using a Java plugin? I have modified the stash asynchronous post receive sample code to look for it and it does not seem to be set.

            Thanks,
            James

            James Gray added a comment - Hi, Is REMOTE_USER still applicable when using a Java plugin? I have modified the stash asynchronous post receive sample code to look for it and it does not seem to be set. Thanks, James

            TimP added a comment - - edited

            As of 1.1, Stash will set the REMOTE_USER environment variable to the authenticated Stash user's username when executing Git hosting commands over both HTTP and SSH. You can use this environment variable in any git hooks registered in your Stash repositories.

            TimP added a comment - - edited As of 1.1, Stash will set the REMOTE_USER environment variable to the authenticated Stash user's username when executing Git hosting commands over both HTTP and SSH. You can use this environment variable in any git hooks registered in your Stash repositories.

              Unassigned Unassigned
              mheemskerk Michael Heemskerk (Inactive)
              Votes:
              4 Vote for this issue
              Watchers:
              10 Start watching this issue

                Created:
                Updated:
                Resolved: