Add support for an inclusive job list in Jenkins plugin (#8287)
* Add support for an inclusive job list * Update jenkins plugin tests * Update jenkins plugin docs * Update jenkins plugin docs
This commit is contained in:
parent
2c61fad895
commit
ed72aac0be
|
|
@ -39,11 +39,14 @@ This plugin does not require a plugin on jenkins and it makes use of Jenkins API
|
|||
## empty will use default value 10
|
||||
# max_subjob_per_layer = 10
|
||||
|
||||
## Jobs to exclude from gathering
|
||||
# job_exclude = [ "job1", "job2/subjob1/subjob2", "job3/*"]
|
||||
## Jobs to include or exclude from gathering
|
||||
## When using both lists, job_exclude has priority.
|
||||
## Wildcards are supported: [ "jobA/*", "jobB/subjob1/*"]
|
||||
# job_include = [ "*" ]
|
||||
# job_exclude = [ ]
|
||||
|
||||
## Nodes to exclude from gathering
|
||||
# node_exclude = [ "node1", "node2" ]
|
||||
# node_exclude = [ ]
|
||||
|
||||
## Worker pool for jenkins plugin only
|
||||
## Empty this field will use default value 5
|
||||
|
|
|
|||
|
|
@ -37,7 +37,9 @@ type Jenkins struct {
|
|||
MaxSubJobDepth int `toml:"max_subjob_depth"`
|
||||
MaxSubJobPerLayer int `toml:"max_subjob_per_layer"`
|
||||
JobExclude []string `toml:"job_exclude"`
|
||||
jobFilter filter.Filter
|
||||
JobInclude []string `toml:"job_include"`
|
||||
jobFilterExclude filter.Filter
|
||||
jobFilterInclude filter.Filter
|
||||
|
||||
NodeExclude []string `toml:"node_exclude"`
|
||||
nodeFilter filter.Filter
|
||||
|
|
@ -77,11 +79,14 @@ const sampleConfig = `
|
|||
## empty will use default value 10
|
||||
# max_subjob_per_layer = 10
|
||||
|
||||
## Jobs to exclude from gathering
|
||||
# job_exclude = [ "job1", "job2/subjob1/subjob2", "job3/*"]
|
||||
## Jobs to include or exclude from gathering
|
||||
## When using both lists, job_exclude has priority.
|
||||
## Wildcards are supported: [ "jobA/*", "jobB/subjob1/*"]
|
||||
# job_include = [ "*" ]
|
||||
# job_exclude = [ ]
|
||||
|
||||
## Nodes to exclude from gathering
|
||||
# node_exclude = [ "node1", "node2" ]
|
||||
# node_exclude = [ ]
|
||||
|
||||
## Worker pool for jenkins plugin only
|
||||
## Empty this field will use default value 5
|
||||
|
|
@ -157,8 +162,13 @@ func (j *Jenkins) initialize(client *http.Client) error {
|
|||
}
|
||||
j.Source = u.Hostname()
|
||||
|
||||
// init job filter
|
||||
j.jobFilter, err = filter.Compile(j.JobExclude)
|
||||
// init job filters
|
||||
j.jobFilterExclude, err = filter.Compile(j.JobExclude)
|
||||
if err != nil {
|
||||
return fmt.Errorf("error compile job filters[%s]: %v", j.URL, err)
|
||||
}
|
||||
|
||||
j.jobFilterInclude, err = filter.Compile(j.JobInclude)
|
||||
if err != nil {
|
||||
return fmt.Errorf("error compile job filters[%s]: %v", j.URL, err)
|
||||
}
|
||||
|
|
@ -303,8 +313,14 @@ func (j *Jenkins) getJobDetail(jr jobRequest, acc telegraf.Accumulator) error {
|
|||
if j.MaxSubJobDepth > 0 && jr.layer == j.MaxSubJobDepth {
|
||||
return nil
|
||||
}
|
||||
|
||||
// filter out not included job.
|
||||
if j.jobFilterInclude != nil && j.jobFilterInclude.Match(jr.hierarchyName()) == false {
|
||||
return nil
|
||||
}
|
||||
|
||||
// filter out excluded job.
|
||||
if j.jobFilter != nil && j.jobFilter.Match(jr.hierarchyName()) {
|
||||
if j.jobFilterExclude != nil && j.jobFilterExclude.Match(jr.hierarchyName()) {
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -368,6 +368,7 @@ func TestInitialize(t *testing.T) {
|
|||
Log: testutil.Logger{},
|
||||
URL: ts.URL,
|
||||
ResponseTimeout: internal.Duration{Duration: time.Microsecond},
|
||||
JobInclude: []string{"jobA", "jobB"},
|
||||
JobExclude: []string{"job1", "job2"},
|
||||
NodeExclude: []string{"node1", "node2"},
|
||||
},
|
||||
|
|
@ -806,6 +807,9 @@ func TestGatherJobs(t *testing.T) {
|
|||
URL: ts.URL,
|
||||
MaxBuildAge: internal.Duration{Duration: time.Hour},
|
||||
ResponseTimeout: internal.Duration{Duration: time.Microsecond},
|
||||
JobInclude: []string{
|
||||
"*",
|
||||
},
|
||||
JobExclude: []string{
|
||||
"ignore-1",
|
||||
"apps/ignore-all/*",
|
||||
|
|
|
|||
Loading…
Reference in New Issue