From 7ba6170e12050ee0cd41d652963539d09547f3e2 Mon Sep 17 00:00:00 2001 From: Bo-Yi Wu Date: Mon, 16 Jan 2017 15:04:12 +0800 Subject: [PATCH] fix: show error if missing jobs. --- plugin.go | 9 ++++++++- plugin_test.go | 16 ++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/plugin.go b/plugin.go index 7a69b8e..2001fd8 100644 --- a/plugin.go +++ b/plugin.go @@ -36,13 +36,20 @@ func (p Plugin) Exec() error { return errors.New("missing jenkins config") } + jobs := trimElement(p.Job) + + if len(jobs) == 0 { + return errors.New("missing jenkins job") + } + auth := &Auth{ Username: p.Username, Token: p.Token, } + jenkins := NewJenkins(auth, p.BaseURL) - for _, value := range trimElement(p.Job) { + for _, value := range jobs { jenkins.trigger(value, nil) } diff --git a/plugin_test.go b/plugin_test.go index 9957ff9..6b67199 100644 --- a/plugin_test.go +++ b/plugin_test.go @@ -24,6 +24,22 @@ func TestMissingJenkinsConfig(t *testing.T) { assert.NotNil(t, err) } +func TestMissingJenkinsJob(t *testing.T) { + plugin := Plugin{ + BaseURL: "http://example.com", + Username: "foo", + Token: "bar", + } + + err := plugin.Exec() + assert.NotNil(t, err) + + plugin.Job = []string{" "} + + err = plugin.Exec() + assert.NotNil(t, err) +} + func TestPluginTriggerBuild(t *testing.T) { plugin := Plugin{ BaseURL: "http://example.com",