feat: support parameter handling for dynamic URL paths (#35)

- Comment out unused form data encoding in `post` method
- Remove redundant error logging in `post` method
- Add conditional URL path selection in `trigger` method based on parameters
- Add `parameter` flag to CLI options in `main.go`
- Include `parameter` in the `run` function configuration
- Import `net/url` package in `plugin.go`
- Add `Parameter` field to `plugin.go` struct
- Parse and add parameters to URL values in `Exec` method
- Pass parsed parameters to `trigger` method in `Exec` function

Signed-off-by: appleboy <appleboy.tw@gmail.com>
This commit is contained in:
Bo-Yi Wu
2024-10-05 20:25:01 +08:00
committed by GitHub
parent bb1e9fe4e0
commit a7c6b81621
3 changed files with 35 additions and 15 deletions
+16 -6
View File
@@ -3,17 +3,19 @@ package main
import (
"errors"
"log"
"net/url"
"strings"
)
type (
// Plugin values.
Plugin struct {
BaseURL string
Username string
Token string
Job []string
Insecure bool
BaseURL string
Username string
Token string
Job []string
Insecure bool
Parameter []string
}
)
@@ -50,8 +52,16 @@ func (p Plugin) Exec() error {
jenkins := NewJenkins(auth, p.BaseURL, p.Insecure)
params := url.Values{}
for _, v := range p.Parameter {
kv := strings.Split(v, "=")
if len(kv) == 2 {
params.Add(kv[0], kv[1])
}
}
for _, v := range jobs {
if err := jenkins.trigger(v, nil); err != nil {
if err := jenkins.trigger(v, params); err != nil {
return err
}
log.Printf("trigger job %s success", v)