From 6de21202e8118abe2b58b6aef4cdc763846cc34c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20S=C4=99k?= Date: Sat, 11 Jan 2020 16:01:25 +0100 Subject: [PATCH] Fix get Jenkins plugins through Jenkins API --- pkg/controller/jenkins/client/jenkins.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/pkg/controller/jenkins/client/jenkins.go b/pkg/controller/jenkins/client/jenkins.go index c8ae39d1..27022a8c 100644 --- a/pkg/controller/jenkins/client/jenkins.go +++ b/pkg/controller/jenkins/client/jenkins.go @@ -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 +}