diff --git a/server/forge/bitbucketdatacenter/bitbucketdatacenter.go b/server/forge/bitbucketdatacenter/bitbucketdatacenter.go index f182b3788..ea36e8b24 100644 --- a/server/forge/bitbucketdatacenter/bitbucketdatacenter.go +++ b/server/forge/bitbucketdatacenter/bitbucketdatacenter.go @@ -579,6 +579,14 @@ func (c *client) updatePipelineFromCommits(ctx context.Context, u *model.User, r if err != nil { return nil, fmt.Errorf("unable to read commit: %w", err) } + + // In Bitbucket Data Center, when using annotated tags, the webhook's ToHash is the tag object SHA, not the actual commit SHA. + // Update p.Commit so that build statuses are posted to the correct commit SHA. + if p.Event == model.EventTag && commit.ID != "" && commit.ID != p.Commit { + p.Commit = commit.ID + p.ForgeURL = fmt.Sprintf("%s/projects/%s/repos/%s/commits/%s", c.url, r.Owner, r.Name, commit.ID) + } + p.Message = commit.Message opts := &bb.CompareChangesOptions{}