CLI tool to interface with GoCD Server.
brew tap drewsonne/tap
brew install go-gocd
Download the latest release from https://github.com/drewsonne/go-gocd/releases,
and place the binary in your $PATH
.
$ gocd configure
? GoCD Server (should contain '/go/' suffix) https://my-go-server:8154/go/
? Client Username my_user
? Client Password *****
? Skip SSL certificate validation (y/N) N
$ gocd list-agents
The library can either be configured using environment variables, cli flags, or a yaml config file.
Name | CLI Flag | YAML | Environment Variable |
---|---|---|---|
GoCD Server (with /go/ suffix) |
--server |
server |
$GOCD_SERVER |
Username | --username |
username |
$GOCD_USERNAME |
Password | --password |
password |
$GOCD_PASSWORD |
Skip HTTPS/SSL Certification Check | --skip_ssl_check |
skip_ssl_check |
$GOCD_SKIP_SSL_CHECK |
Run gocd configure
to launch a wizard which will create a file at ~/.gocd.conf
, or create the file manually:
default:
server: https://goserver:8154/go
username: admin
password: mypassword
skip_ssl_check: true
Authentication credentials for multiple gocd servers can be stored by using the --profile
flag.
Configuration Profiles can be created using:
gocd --profile other-server configure
Which will create a new configuration block in ~/.beamly.conf
Configuration profiles can be used by specifying --profile
before your command
gocd --profile other-server list-agents
$ gocd -help
Construct a new GoCD client and supply the URL to your GoCD server and if required, username and password. Then use the various services on the client to access different parts of the GoCD API. For example:
package main
import (
"github.com/drewsonne/go-gocd/gocd"
"context"
"fmt"
)
func main() {
cfg := gocd.Configuration{
Server: "https://my_gocd/go/",
Username: "ApiUser",
Password: "MySecretPassword",
}
c := cfg.Client()
// list all agents in use by the GoCD Server
var a []*gocd.Agent
var err error
var r *gocd.APIResponse
if a, r, err = c.Agents.List(context.Background()); err != nil {
if r.HTTP.StatusCode == 404 {
fmt.Println("Couldn't find agent")
} else {
panic(err)
}
}
fmt.Println(a)
}
If you wish to use your own http client, you can use the following idiom
package main
import (
"github.com/drewsonne/go-gocd/gocd"
"net/http"
"context"
)
func main() {
client := gocd.NewClient(
&gocd.Configuration{},
&http.Client{},
)
client.Login(context.Background())
}
This library is still in pre-release. It was initially developed to be an interface for a gocd terraform provider, which, at this stage, will heavily influence the direction of this library. A list of new features and the expected release schedule for those features can be found in the project for this github repository.
This library's structure was initially inspired by https://github.com/google/go-github. There may still be some vestigial code and structures from this library which will be removed in future revisions and before v1.0.0 of this library.
This library is distributed under the Apache 2.0 license found in LICENSE file.