feat: improve logging and error handling in Jenkins plugin

- Add error handling for unexpected response codes in `post` method of `jenkins.go`
- Import `log` package in `plugin.go`
- Add logging for successful job trigger in `Exec` method of `plugin.go`

Signed-off-by: appleboy <appleboy.tw@gmail.com>
This commit is contained in:
appleboy
2024-10-05 13:28:14 +08:00
parent 1bb020b22d
commit bb1e9fe4e0
2 changed files with 6 additions and 0 deletions
+4
View File
@@ -93,6 +93,10 @@ func (jenkins *Jenkins) post(path string, params url.Values, body interface{}) (
return
}
if resp.StatusCode != http.StatusCreated {
return fmt.Errorf("unexpected response code: %d", resp.StatusCode)
}
return jenkins.parseResponse(resp, body)
}
+2
View File
@@ -2,6 +2,7 @@ package main
import (
"errors"
"log"
"strings"
)
@@ -53,6 +54,7 @@ func (p Plugin) Exec() error {
if err := jenkins.trigger(v, nil); err != nil {
return err
}
log.Printf("trigger job %s success", v)
}
return nil