diff --git a/README.md b/README.md index 2540c3130..ca66f554a 100644 --- a/README.md +++ b/README.md @@ -229,6 +229,7 @@ publish: container: drone source: /tmp/drone.deb target: latest/drone.deb + branch: master ``` @@ -248,6 +249,10 @@ Drone currently has these `deploy` and `publish` plugins implemented (more to co - [OpenStack Swift](#docs) - [PyPI](#docs) +Publish plugins can be limited to a specific branch using the `branch` configuration +as seen above in the `swift` example. If you do not specify a `branch` all branches +will be published, with the exception of Pull Requests. + ### Notifications Drone can trigger email, hipchat and web hook notification at the beginning and diff --git a/pkg/build/build.go b/pkg/build/build.go index d87c82c99..3a4a6ff55 100644 --- a/pkg/build/build.go +++ b/pkg/build/build.go @@ -517,7 +517,7 @@ func (b *Builder) writeBuildScript(dir string) error { // we should only execute the build commands, // and omit the deploy and publish commands. if len(b.Repo.PR) == 0 { - b.Build.Write(f) + b.Build.Write(f, b.Repo) } else { // only write the build commands b.Build.WriteBuild(f) diff --git a/pkg/build/script/script.go b/pkg/build/script/script.go index d2ca5dfb3..394f0a9bc 100644 --- a/pkg/build/script/script.go +++ b/pkg/build/script/script.go @@ -10,6 +10,7 @@ import ( "github.com/drone/drone/pkg/build/buildfile" "github.com/drone/drone/pkg/build/git" + "github.com/drone/drone/pkg/build/repo" "github.com/drone/drone/pkg/plugin/deploy" "github.com/drone/drone/pkg/plugin/notify" "github.com/drone/drone/pkg/plugin/publish" @@ -81,13 +82,13 @@ type Build struct { // Write adds all the steps to the build script, including // build commands, deploy and publish commands. -func (b *Build) Write(f *buildfile.Buildfile) { +func (b *Build) Write(f *buildfile.Buildfile, r *repo.Repo) { // append build commands b.WriteBuild(f) // write publish commands if b.Publish != nil { - b.Publish.Write(f) + b.Publish.Write(f, r) } // write deployment commands diff --git a/pkg/plugin/publish/publish.go b/pkg/plugin/publish/publish.go index 2cfbf6deb..93dceb184 100644 --- a/pkg/plugin/publish/publish.go +++ b/pkg/plugin/publish/publish.go @@ -2,6 +2,7 @@ package publish import ( "github.com/drone/drone/pkg/build/buildfile" + "github.com/drone/drone/pkg/build/repo" ) // Publish stores the configuration details @@ -13,14 +14,19 @@ type Publish struct { PyPI *PyPI `yaml:"pypi,omitempty"` } -func (p *Publish) Write(f *buildfile.Buildfile) { - if p.S3 != nil { +func (p *Publish) Write(f *buildfile.Buildfile, r *repo.Repo) { + // S3 + if p.S3 != nil && (len(p.S3.Branch) == 0 || (len(p.S3.Branch) > 0 && r.Branch == p.S3.Branch)) { p.S3.Write(f) } - if p.Swift != nil { + + // Swift + if p.Swift != nil && (len(p.Swift.Branch) == 0 || (len(p.Swift.Branch) > 0 && r.Branch == p.Swift.Branch)) { p.Swift.Write(f) } - if p.PyPI != nil { + + // PyPI + if p.PyPI != nil && (len(p.PyPI.Branch) == 0 || (len(p.PyPI.Branch) > 0 && r.Branch == p.PyPI.Branch)) { p.PyPI.Write(f) } } diff --git a/pkg/plugin/publish/pypi.go b/pkg/plugin/publish/pypi.go index 4b3ee1472..998497838 100644 --- a/pkg/plugin/publish/pypi.go +++ b/pkg/plugin/publish/pypi.go @@ -2,6 +2,7 @@ package publish import ( "fmt" + "github.com/drone/drone/pkg/build/buildfile" ) @@ -36,6 +37,7 @@ type PyPI struct { Password string `yaml:"password,omitempty"` Formats []string `yaml:"formats,omitempty"` Repository string `yaml:"repository,omitempty"` + Branch string `yaml:"branch,omitempty"` } func (p *PyPI) Write(f *buildfile.Buildfile) {