Fix get Jenkins plugins through Jenkins API

This commit is contained in:
Tomasz Sęk 2020-01-11 16:01:25 +01:00
parent 7ca7e58cc5
commit 6de21202e8
No known key found for this signature in database
GPG Key ID: DC356D23F6A644D0
1 changed files with 14 additions and 0 deletions

View File

@ -172,3 +172,17 @@ func (jenkins *jenkins) GetNodeSecret(name string) (string, error) {
return result["secret"], nil
}
// Returns the list of all plugins installed on the Jenkins server.
// You can supply depth parameter, to limit how much data is returned.
func (jenkins *jenkins) GetPlugins(depth int) (*gojenkins.Plugins, error) {
p := gojenkins.Plugins{Jenkins: &jenkins.Jenkins, Raw: new(gojenkins.PluginResponse), Base: "/pluginManager", Depth: depth}
statusCode, err := p.Poll()
if err != nil {
return nil, err
}
if statusCode != http.StatusOK {
return nil, fmt.Errorf("invalid status code returned: %d", statusCode)
}
return &p, nil
}