Merge pull request #291 from sivel/restrict-publish-branch

Add the ability to restrict publish plugins to a specific branch
This commit is contained in:
Brad Rydzewski 2014-05-01 16:51:30 -04:00
commit cc9c6c9bde
5 changed files with 21 additions and 7 deletions

View file

@ -229,6 +229,7 @@ publish:
container: drone container: drone
source: /tmp/drone.deb source: /tmp/drone.deb
target: latest/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) - [OpenStack Swift](#docs)
- [PyPI](#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 ### Notifications
Drone can trigger email, hipchat and web hook notification at the beginning and Drone can trigger email, hipchat and web hook notification at the beginning and

View file

@ -517,7 +517,7 @@ func (b *Builder) writeBuildScript(dir string) error {
// we should only execute the build commands, // we should only execute the build commands,
// and omit the deploy and publish commands. // and omit the deploy and publish commands.
if len(b.Repo.PR) == 0 { if len(b.Repo.PR) == 0 {
b.Build.Write(f) b.Build.Write(f, b.Repo)
} else { } else {
// only write the build commands // only write the build commands
b.Build.WriteBuild(f) b.Build.WriteBuild(f)

View file

@ -10,6 +10,7 @@ import (
"github.com/drone/drone/pkg/build/buildfile" "github.com/drone/drone/pkg/build/buildfile"
"github.com/drone/drone/pkg/build/git" "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/deploy"
"github.com/drone/drone/pkg/plugin/notify" "github.com/drone/drone/pkg/plugin/notify"
"github.com/drone/drone/pkg/plugin/publish" "github.com/drone/drone/pkg/plugin/publish"
@ -81,13 +82,13 @@ type Build struct {
// Write adds all the steps to the build script, including // Write adds all the steps to the build script, including
// build commands, deploy and publish commands. // 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 // append build commands
b.WriteBuild(f) b.WriteBuild(f)
// write publish commands // write publish commands
if b.Publish != nil { if b.Publish != nil {
b.Publish.Write(f) b.Publish.Write(f, r)
} }
// write deployment commands // write deployment commands

View file

@ -2,6 +2,7 @@ package publish
import ( import (
"github.com/drone/drone/pkg/build/buildfile" "github.com/drone/drone/pkg/build/buildfile"
"github.com/drone/drone/pkg/build/repo"
) )
// Publish stores the configuration details // Publish stores the configuration details
@ -13,14 +14,19 @@ type Publish struct {
PyPI *PyPI `yaml:"pypi,omitempty"` PyPI *PyPI `yaml:"pypi,omitempty"`
} }
func (p *Publish) Write(f *buildfile.Buildfile) { func (p *Publish) Write(f *buildfile.Buildfile, r *repo.Repo) {
if p.S3 != nil { // S3
if p.S3 != nil && (len(p.S3.Branch) == 0 || (len(p.S3.Branch) > 0 && r.Branch == p.S3.Branch)) {
p.S3.Write(f) 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) 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) p.PyPI.Write(f)
} }
} }

View file

@ -2,6 +2,7 @@ package publish
import ( import (
"fmt" "fmt"
"github.com/drone/drone/pkg/build/buildfile" "github.com/drone/drone/pkg/build/buildfile"
) )
@ -36,6 +37,7 @@ type PyPI struct {
Password string `yaml:"password,omitempty"` Password string `yaml:"password,omitempty"`
Formats []string `yaml:"formats,omitempty"` Formats []string `yaml:"formats,omitempty"`
Repository string `yaml:"repository,omitempty"` Repository string `yaml:"repository,omitempty"`
Branch string `yaml:"branch,omitempty"`
} }
func (p *PyPI) Write(f *buildfile.Buildfile) { func (p *PyPI) Write(f *buildfile.Buildfile) {