-
-
Notifications
You must be signed in to change notification settings - Fork 78
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support to print the labels of Jenkins (#701)
- Loading branch information
1 parent
e69a681
commit f429dc3
Showing
4 changed files
with
65 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
"github.com/jenkins-zh/jenkins-client/pkg/core" | ||
"github.com/spf13/cobra" | ||
"net/http" | ||
) | ||
|
||
type labelOption struct { | ||
RoundTripper http.RoundTripper | ||
} | ||
|
||
func newCenterLabelCommand() (cmd *cobra.Command) { | ||
opt := &labelOption{} | ||
cmd = &cobra.Command{ | ||
Use: "labels", | ||
Short: "Print all the labels of the Jenkins agents", | ||
RunE: opt.runE, | ||
} | ||
return | ||
} | ||
|
||
func (o *labelOption) runE(cmd *cobra.Command, args []string) (err error) { | ||
jClient := &core.Client{ | ||
JenkinsCore: core.JenkinsCore{ | ||
RoundTripper: o.RoundTripper, | ||
}, | ||
} | ||
getCurrentJenkinsAndClientV2(&(jClient.JenkinsCore)) | ||
var labelsRes *core.LabelsResponse | ||
if labelsRes, err = jClient.GetLabels(); err == nil { | ||
if labelsRes.Status == "ok" { | ||
for i := range labelsRes.Data { | ||
cmd.Println(labelsRes.Data[i].Label) | ||
} | ||
} else { | ||
err = fmt.Errorf("failed to get labels, status: %s", labelsRes.Status) | ||
} | ||
} | ||
return | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters