I want when client push code to repo then repo handle request and pull code to myserver, how to work it ?
Community moderators have prevented the ability to post new answers.
How I solved this task:
Configured the plugin with the following POST Url:
http://myMachine:8002/pushed?useremail=${user.email}&$projectname={project.name}&projectkey=${project.key}&repositoryname=${repository.name}&repositoryslug=${repository.slug}
On my local machine (myMachine), where I want the code pulled to, I implemented a simple web-server, which listens on port 8002 (see above). This webserver waits for receiving the request above. If the webserver gets the request, it automatically pulls the repository from Bitbucket-Server.
It's a really tiny web-server, scripted in Perl using Dancer (I shortened it a little (removed output - but it still should work)
use Dancer2; use Path::Tiny; use Git::Repository; set serializer => 'JSON'; set port => 8002; set logger => "Console::Colored"; set log => 'debug'; get '/' => sub{ return {message => "Server to perform forced pull of local repository from BITBUCKET"}; }; post '/pushed' => sub { my $p; my $icnt = 0; my %p = params; foreach my $currItem (keys(%p)){ $icnt++; $p = "?" if $icnt==1; $p .= "&" if $icnt>1; $p .= $currItem."=".$p{$currItem} } debug (request->path.$p); my $email = params->{useremail}?params->{useremail}:"UNKNOWN"; my $pn = params->{projectname}?params->{projectname}:"UNKNOWN"; my $pk = params->{projectkey}?params->{projectkey}:"UNKNOWN"; my $rn = params->{repositoryname}?params->{repositoryname}:"UNKNOWN"; my $rs = params->{repositoryslug}?params->{repositoryslug}:"UNKNOWN"; if ($pk =~ m{myDesiredBitbucketProject}ix) { if ($rs =~ m{myDesiredRepository}ix) { my $path = path("D:\projects\myDesiredRepository"); my $savePath = Path::Tiny->cwd; chdir $path->stringify; my $r = Git::Repository->new( work_tree => $path->stringify ); my $cmd = $r->command( 'reset', '--hard' ); $cmd->close; $cmd = $r->command( 'fetch', 'origin' ); $cmd->close; $cmd = $r->command( 'reset', '--hard', 'origin/master' ); @output = $cmd->stdout->getlines(); $cmd->close; chdir $savePath->stringify; return {message => @output}; } } return {message => "Pushed to Project <$pn> (<$pk>), Repository <$rn> (<$rs>) by $email"}; }; any qr{.*} => sub { #status 'not_found'; #template 'special_404', { path => request->path }; warning ("Called Invalid route <".request->path.">"); }; dance;
There is a similar approach described here: https://scriptrunner.adaptavist.com/latest/bitbucket/PostReceiveHooks.html#_update_static_site
Except that the update initiated via the BB server.
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.