go-jenkins is a Go client library for accessing the Jenkins API. It provides a simple and efficient way to interact with Jenkins programmatically.
go-jenkins is compatible with modern Go releases in module mode. To install the package, use the following command:
go get github.com/yarlson/go-jenkins
To use go-jenkins in your Go code, import it as follows:
import "github.com/yarlson/go-jenkins/jenkins"
Here's a basic example of how to use the library to create a new Jenkins node:
package main
import (
"context"
"fmt"
"github.com/yarlson/go-jenkins/jenkins"
)
func main() {
client, err := jenkins.NewClient(
jenkins.WithBaseURL("http://localhost:8080"),
jenkins.WithUserPassword("admin", "admin"),
)
if err != nil {
panic(err)
}
node, _, err := client.Nodes.Create(context.Background(), &jenkins.Node{
Name: "test-node",
Description: "",
RemoteFS: "/var/lib/jenkins",
NumExecutors: 1,
Mode: jenkins.NodeModeExclusive,
Labels: []string{"test"},
})
if err != nil {
panic(err)
}
fmt.Println(node)
}
This example demonstrates how to create a new Jenkins client and use it to create a new node.
For detailed API documentation, please refer to the GoDoc reference.
The library currently supports the following Jenkins API operations:
- Node management (create, list, get, update, delete)
- JNLP and SSH launcher configurations
- Various node properties and configurations
Contributions to go-jenkins are welcome! If you'd like to contribute, please follow these steps:
- Fork the repository
- Create a new branch for your feature or bug fix
- Write your code and tests
- Ensure all tests pass
- Submit a pull request
Please make sure to update tests as appropriate and adhere to the existing coding style.
To run the tests for go-jenkins, use the following command:
go test ./...
The project uses GitHub Actions for continuous integration. You can view the current test status by clicking on the "Test Status" badge at the top of this README.
go-jenkins is released under the BSD-style license. For more details, see the LICENSE file in the repository.
For any issues, questions, or suggestions, please open an issue on the GitHub repository.