Skip to content

Commit

Permalink
fix: show error if missing jobs.
Browse files Browse the repository at this point in the history
  • Loading branch information
appleboy committed Jan 16, 2017
1 parent 4ce3a1e commit 7ba6170
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
9 changes: 8 additions & 1 deletion plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
16 changes: 16 additions & 0 deletions plugin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 7ba6170

Please sign in to comment.