Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add bitbucket datacenter (server) support #2503

Merged
merged 54 commits into from
Feb 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
9f38545
feat: Re-introduce bitbucket server support with completely rewritten…
langecode Sep 27, 2023
38ca877
fix: Woodpecker now using remote forge ID to fetch repository
langecode Sep 27, 2023
bd09043
feat: Remove code references denoting Bitbucket DataCenter/Server as …
langecode Sep 28, 2023
c209deb
fix: Changed the old versioned doc by mistake
langecode Sep 28, 2023
2230508
chore: A few changes from PR comments
langecode Sep 28, 2023
d0bd496
fix: Need to set remote forge ID on user
langecode Sep 28, 2023
894a561
fix: Go linting issues
langecode Sep 29, 2023
3e5fa11
fix: Vue linting issues
langecode Sep 29, 2023
ca2a127
fix: Bitbucket icon, rename forge to bitbucketdatacenter
langecode Oct 2, 2023
1159527
chore: Keep in sync with upstrame main
langecode Oct 2, 2023
7dd9425
fix: Only fetch repos with at least write permission since only repos…
langecode Oct 2, 2023
51dcb15
fix: Unittest failed after new permission mapping
langecode Oct 2, 2023
a6dbfc6
feat: Updating documentation on Bitbucket Datacenter
langecode Oct 3, 2023
7184cc5
feat: Using repo hash as HMAC key for Bitbucket webhook
langecode Oct 3, 2023
9f0d01c
chore: Merge in changes from upstream/main
langecode Oct 3, 2023
ed69d79
chore: Merging from upstream/main
langecode Oct 9, 2023
719b338
fix: Do not trigger build on deleted refs
langecode Oct 23, 2023
887395f
chore: Merge from upstream/main
langecode Oct 23, 2023
2a48a4e
chore: Merge remote-tracking branch 'upstream/main' into feature/rein…
langecode Oct 23, 2023
7d58400
chore: Merge from upstream/main
langecode Oct 26, 2023
32de185
chore: Merge from upstream/main
langecode Nov 8, 2023
d13d2e3
chore: Ensure mark-down formatting
langecode Nov 8, 2023
7a9af68
fix: Markdown linting
langecode Nov 8, 2023
e782eb6
chore: Merge from upstream/main
langecode Jan 3, 2024
3fd99dd
chore: Adjustments as per review suggestions
langecode Jan 3, 2024
de63194
fix: Small change to aling conversion of BB id to ForgeID
langecode Jan 3, 2024
d858543
chore: Merge from upstream/main
langecode Jan 26, 2024
e4135fd
fix: Linting issues
langecode Jan 26, 2024
9c3e99b
feat: Aligning environment variable naming as per review suggestion
langecode Jan 26, 2024
96dc63d
chore: Upgrade from upstream
langecode Feb 2, 2024
ec4f139
chore: Note around Bitbiucket and OAuth 1.0 as per review suggestion
langecode Feb 2, 2024
2184e93
chore: Merge remote-tracking branch 'upstream/main' into feature/rein…
langecode Feb 6, 2024
b2b331d
chore: Updated go.sum after merge from main
langecode Feb 6, 2024
9bc2414
fix: PRs should be enabled for Bitbucket repos
langecode Feb 6, 2024
8acd343
chore: Update docs/docs/91-migrations.md
langecode Feb 7, 2024
cedb015
Ignore gitlab push events without commits (#3339)
lukashass Feb 7, 2024
4db6e65
Ignore gitlab merge request events without code changes (#3338)
lukashass Feb 7, 2024
2cfe0f6
Fix version check on next (#3340)
lukashass Feb 7, 2024
c85cc1c
chore: Merge remote-tracking branch 'upstream/main' into feature/rein…
langecode Feb 7, 2024
05e694e
Merge remote-tracking branch 'upstream/main' into feature/reintroduce…
langecode Feb 8, 2024
caccf5b
chore: Update docs/docs/30-administration/11-forges/60-bitbucket_data…
langecode Feb 8, 2024
bea9dcc
fix: Removing whitespace added by commit directly from PR
langecode Feb 8, 2024
0a1ba54
chore: Merge from main
langecode Feb 19, 2024
b9d01fd
feat: Migrated to OAuth 2.0 and introduced pull-request closed event
langecode Feb 20, 2024
045226e
chore: Small rename
langecode Feb 20, 2024
59fc8a3
fix: Missing org mapping
langecode Feb 20, 2024
0083d3b
chore: Remove migration information
langecode Feb 20, 2024
fb6abd2
chore: Reducing the level of headings in toc
langecode Feb 20, 2024
5620f84
fix: go mod tidy
langecode Feb 20, 2024
5df1643
chore: Linting issue
langecode Feb 20, 2024
a6f247e
fix: markdown formatting
langecode Feb 20, 2024
78d98cc
fix: Fix issues with using refresh token towards bitbucket
langecode Feb 20, 2024
63ed596
chore: Fixing license headers
langecode Feb 20, 2024
400fbc9
chore: Merge remote-tracking branch 'upstream/main' into feature/rein…
langecode Feb 20, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions cmd/server/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,43 @@ var flags = append([]cli.Flag{
Usage: "gitlab skip ssl verification",
},
//
// Bitbucket DataCenter/Server (previously Stash)
//
&cli.BoolFlag{
EnvVars: []string{"WOODPECKER_BITBUCKET_DC"},
Name: "bitbucket-dc",
Usage: "Bitbucket DataCenter/Server driver is enabled",
},
&cli.StringFlag{
EnvVars: []string{"WOODPECKER_BITBUCKET_DC_URL"},
Name: "bitbucket-dc-server",
Usage: "Bitbucket DataCenter/Server server address",
},
&cli.StringFlag{
EnvVars: []string{"WOODPECKER_BITBUCKET_DC_CLIENT_ID"},
Name: "bitbucket-dc-client-id",
Usage: "Bitbucket DataCenter/Server OAuth 2.0 client id",
FilePath: os.Getenv("WOODPECKER_BITBUCKET_DC_CLIENT_ID_FILE"),
},
&cli.StringFlag{
EnvVars: []string{"WOODPECKER_BITBUCKET_DC_CLIENT_SECRET"},
Name: "bitbucket-dc-client-secret",
Usage: "Bitbucket DataCenter/Server OAuth 2.0 client secret",
FilePath: os.Getenv("WOODPECKER_BITBUCKET_DC_CLIENT_SECRET_FILE"),
},
&cli.StringFlag{
EnvVars: []string{"WOODPECKER_BITBUCKET_DC_GIT_USERNAME"},
Name: "bitbucket-dc-git-username",
Usage: "Bitbucket DataCenter/Server service account username",
FilePath: os.Getenv("WOODPECKER_BITBUCKET_DC_GIT_USERNAME_FILE"),
},
&cli.StringFlag{
EnvVars: []string{"WOODPECKER_BITBUCKET_DC_GIT_PASSWORD"},
Name: "bitbucket-dc-git-password",
Usage: "Bitbucket DataCenter/Server service account password",
FilePath: os.Getenv("WOODPECKER_BITBUCKET_DC_GIT_PASSWORD_FILE"),
},
//
// development flags
//
&cli.StringFlag{
Expand Down
16 changes: 16 additions & 0 deletions cmd/server/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import (
"go.woodpecker-ci.org/woodpecker/v2/server/cache"
"go.woodpecker-ci.org/woodpecker/v2/server/forge"
"go.woodpecker-ci.org/woodpecker/v2/server/forge/bitbucket"
"go.woodpecker-ci.org/woodpecker/v2/server/forge/bitbucketdatacenter"
"go.woodpecker-ci.org/woodpecker/v2/server/forge/gitea"
"go.woodpecker-ci.org/woodpecker/v2/server/forge/github"
"go.woodpecker-ci.org/woodpecker/v2/server/forge/gitlab"
Expand Down Expand Up @@ -121,6 +122,8 @@ func setupForge(c *cli.Context) (forge.Forge, error) {
return setupGitLab(c)
case c.Bool("bitbucket"):
return setupBitbucket(c)
case c.Bool("bitbucket-dc"):
return setupBitbucketDatacenter(c)
case c.Bool("gitea"):
return setupGitea(c)
default:
Expand Down Expand Up @@ -157,6 +160,19 @@ func setupGitea(c *cli.Context) (forge.Forge, error) {
return gitea.New(opts)
}

// setupBitbucketDatacenter helper function to setup the Bitbucket DataCenter/Server forge from the CLI arguments.
func setupBitbucketDatacenter(c *cli.Context) (forge.Forge, error) {
opts := bitbucketdatacenter.Opts{
URL: c.String("bitbucket-dc-server"),
Username: c.String("bitbucket-dc-git-username"),
Password: c.String("bitbucket-dc-git-password"),
ClientID: c.String("bitbucket-dc-client-id"),
ClientSecret: c.String("bitbucket-dc-client-secret"),
}
log.Trace().Msgf("Forge (bitbucketdatacenter) opts: %#v", opts)
return bitbucketdatacenter.New(opts)
}

// setupGitLab helper function to setup the GitLab forge from the CLI arguments.
func setupGitLab(c *cli.Context) (forge.Forge, error) {
return gitlab.New(gitlab.Opts{
Expand Down
18 changes: 9 additions & 9 deletions docs/docs/30-administration/11-forges/10-overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

## Supported features

| Feature | [GitHub](20-github.md) | [Gitea / Forgejo](30-gitea.md) | [Gitlab](40-gitlab.md) | [Bitbucket](50-bitbucket.md) |
| ------------------------------------------------------------- | :--------------------: | :----------------------------: | :--------------------: | :--------------------------: |
| Event: Push | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: |
| Event: Tag | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: |
| Event: Pull-Request | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: |
| Event: Release | :white_check_mark: | :white_check_mark: | :white_check_mark: | :x: |
| Event: Deploy | :white_check_mark: | :x: | :x: | :x: |
| [Multiple workflows](../../20-usage/25-workflows.md) | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: |
| [when.path filter](../../20-usage/20-workflow-syntax.md#path) | :white_check_mark: | :white_check_mark: | :white_check_mark: | :x: |
| Feature | [GitHub](20-github.md) | [Gitea / Forgejo](30-gitea.md) | [Gitlab](40-gitlab.md) | [Bitbucket](50-bitbucket.md) | [Bitbucket Datacenter](60-bitbucket_datacenter.md) |
| ------------------------------------------------------------- | :--------------------: | :----------------------------: | :--------------------: | :--------------------------: | :------------------------------------------------: |
| Event: Push | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: |
| Event: Tag | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: |
| Event: Pull-Request | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: |
| Event: Release | :white_check_mark: | :white_check_mark: | :white_check_mark: | :x: | :x: |
| Event: Deploy | :white_check_mark: | :x: | :x: | :x: | :x: |
| [Multiple workflows](../../20-usage/25-workflows.md) | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: |
| [when.path filter](../../20-usage/20-workflow-syntax.md#path) | :white_check_mark: | :white_check_mark: | :white_check_mark: | :x: | :x: |
99 changes: 99 additions & 0 deletions docs/docs/30-administration/11-forges/60-bitbucket_datacenter.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
---
toc_max_heading_level: 2
---

# Bitbucket Datacenter / Server
langecode marked this conversation as resolved.
Show resolved Hide resolved

:::warning
Woodpecker comes with experimental support for Bitbucket Datacenter / Server, formerly known as Atlassian Stash.
:::

To enable Bitbucket Server you should configure the Woodpecker container using the following environment variables:

```diff
# docker-compose.yml
version: '3'

services:
woodpecker-server:
[...]
environment:
- [...]
+ - WOODPECKER_BITBUCKET_DC=true
+ - WOODPECKER_BITBUCKET_DC_GIT_USERNAME=foo
+ - WOODPECKER_BITBUCKET_DC_GIT_PASSWORD=bar
+ - WOODPECKER_BITBUCKET_DC_CLIENT_ID=xxx
+ - WOODPECKER_BITBUCKET_DC_CLIENT_SECRET=yyy
+ - WOODPECKER_BITBUCKET_DC_URL=http://stash.mycompany.com

woodpecker-agent:
[...]
```

## Service Account

Woodpecker uses `git+https` to clone repositories, however, Bitbucket Server does not currently support cloning repositories with an OAuth token. To work around this limitation, you must create a service account and provide the username and password to Woodpecker. This service account will be used to authenticate and clone private repositories.
6543 marked this conversation as resolved.
Show resolved Hide resolved

## Registration

Woodpecker must be registered with Bitbucket Datacenter / Server. In the administration section of Bitbucket choose "Application Links" and then "Create link". Woodpecker should be listed as "External Application" and the direction should be set to "Incomming". Note the client id and client secret of the registration to be used in the configuration of Woodpecker.

See also [Configure an incoming link](https://confluence.atlassian.com/bitbucketserver/configure-an-incoming-link-1108483657.html).

## Configuration

This is a full list of configuration options. Please note that many of these options use default configuration values that should work for the majority of installations.

### `WOODPECKER_BITBUCKET_DC`

> Default: `false`

Enables the Bitbucket Server driver.

### `WOODPECKER_BITBUCKET_DC_URL`

> Default: empty

Configures the Bitbucket Server address.

### `WOODPECKER_BITBUCKET_DC_CLIENT_ID`

> Default: empty

Configures your Bitbucket Server OAUth 2.0 client id.

### `WOODPECKER_BITBUCKET_DC_CLIENT_SECRET`

> Default: empty

Configures your Bitbucket Server OAUth 2.0 client secret.

### `WOODPECKER_BITBUCKET_DC_GIT_USERNAME`

> Default: empty

This username is used to authenticate and clone all private repositories.

### `WOODPECKER_BITBUCKET_DC_GIT_USERNAME_FILE`

> Default: empty

Read the value for `WOODPECKER_BITBUCKET_DC_GIT_USERNAME` from the specified filepath

### `WOODPECKER_BITBUCKET_DC_GIT_PASSWORD`

> Default: empty

The password is used to authenticate and clone all private repositories.

### `WOODPECKER_BITBUCKET_DC_GIT_PASSWORD_FILE`

> Default: empty

Read the value for `WOODPECKER_BITBUCKET_DC_GIT_PASSWORD` from the specified filepath

### `WOODPECKER_BITBUCKET_DC_SKIP_VERIFY`

> Default: `false`

Configure if SSL verification should be skipped.
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ require (
github.com/moby/moby v24.0.9+incompatible
github.com/moby/term v0.5.0
github.com/muesli/termenv v0.15.2
github.com/neticdk/go-bitbucket v1.0.0
github.com/oklog/ulid/v2 v2.1.0
github.com/pkg/errors v0.9.1
github.com/prometheus/client_golang v1.18.0
Expand Down Expand Up @@ -111,6 +112,7 @@ require (
github.com/imdario/mergo v0.3.16 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/julienschmidt/httprouter v1.3.0 // indirect
github.com/klauspost/cpuid/v2 v2.2.6 // indirect
github.com/leodido/go-urn v1.2.4 // indirect
github.com/libdns/libdns v0.2.1 // indirect
Expand Down
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,8 @@ github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8Hm
github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y=
github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM=
github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo=
github.com/julienschmidt/httprouter v1.3.0 h1:U0609e9tgbseu3rBINet9P48AI/D3oJs4dN7jwJOQ1U=
github.com/julienschmidt/httprouter v1.3.0/go.mod h1:JR6WtHb+2LUe8TCKY3cZOxFyyO8IZAc4RVcycCCAKdM=
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 h1:Z9n2FFNUXsshfwJMBgNA0RU6/i7WVaAegv3PtuIHPMs=
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51/go.mod h1:CzGEWj7cYgsdH8dAjBGEr58BoE7ScuLd+fwFZ44+/x8=
github.com/kinbiko/jsonassert v1.1.1 h1:DB12divY+YB+cVpHULLuKePSi6+ui4M/shHSzJISkSE=
Expand Down Expand Up @@ -327,6 +329,8 @@ github.com/muesli/termenv v0.15.2 h1:GohcuySI0QmI3wN8Ok9PtKGkgkFIk7y6Vpb5PvrY+Wo
github.com/muesli/termenv v0.15.2/go.mod h1:Epx+iuz8sNs7mNKhxzH4fWXGNpZwUaJKRS1noLXviQ8=
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 h1:C3w9PqII01/Oq1c1nUAm88MOHcQC9l5mIlSMApZMrHA=
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822/go.mod h1:+n7T8mK8HuQTcFwEeznm/DIxMOiR9yIdICNftLE1DvQ=
github.com/neticdk/go-bitbucket v1.0.0 h1:FPvHEgPHoDwD2VHbpyu2R2gnoWQ867RxZd2FivS4wSw=
github.com/neticdk/go-bitbucket v1.0.0/go.mod h1:IrHeWO1CrNi0DlOvfhAA9bGRSeNSUB6/SAfzmwbA5aU=
github.com/oklog/ulid/v2 v2.1.0 h1:+9lhoxAP56we25tyYETBBY1YLA2SaoLvUFgrP2miPJU=
github.com/oklog/ulid/v2 v2.1.0/go.mod h1:rcEKHmBBKfef9DhnvX7y1HZBYxjXb0cP5ExxNsTT1QQ=
github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
Expand Down
Loading