{"id":13493862,"url":"https://github.com/bndr/gojenkins","last_synced_at":"2025-05-14T21:07:38.908Z","repository":{"id":21224194,"uuid":"24538905","full_name":"bndr/gojenkins","owner":"bndr","description":"Jenkins API Client in Go. Looking for maintainers to move this project forward.","archived":false,"fork":false,"pushed_at":"2024-07-26T09:10:49.000Z","size":372,"stargazers_count":877,"open_issues_count":145,"forks_count":450,"subscribers_count":18,"default_branch":"master","last_synced_at":"2025-04-10T09:59:17.502Z","etag":null,"topics":["api","continuous-integration","go","godoc","jenkins"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/bndr.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2014-09-27T18:03:32.000Z","updated_at":"2025-04-06T09:40:48.000Z","dependencies_parsed_at":"2024-09-29T18:00:36.292Z","dependency_job_id":"ce7cb3ca-cb7e-4ff2-b248-fb6482f4edd0","html_url":"https://github.com/bndr/gojenkins","commit_stats":{"total_commits":222,"total_committers":68,"mean_commits":3.264705882352941,"dds":0.7972972972972973,"last_synced_commit":"c316119c46d585335e35a6c8cabf2d2507b87874"},"previous_names":["bndr/go-jenkins"],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bndr%2Fgojenkins","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bndr%2Fgojenkins/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bndr%2Fgojenkins/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bndr%2Fgojenkins/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bndr","download_url":"https://codeload.github.com/bndr/gojenkins/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254227613,"owners_count":22035670,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["api","continuous-integration","go","godoc","jenkins"],"created_at":"2024-07-31T19:01:19.491Z","updated_at":"2025-05-14T21:07:33.793Z","avatar_url":"https://github.com/bndr.png","language":"Go","funding_links":[],"categories":["Go","Repositories"],"sub_categories":[],"readme":"# Jenkins API Client for Go\n\n[![GoDoc](https://godoc.org/github.com/bndr/gojenkins?status.svg)](https://godoc.org/github.com/bndr/gojenkins)\n[![Go Report Cart](https://goreportcard.com/badge/github.com/bndr/gojenkins)](https://goreportcard.com/report/github.com/bndr/gojenkins)\n[![Build Status](https://travis-ci.org/bndr/gojenkins.svg?branch=master)](https://travis-ci.org/bndr/gojenkins)\n\n## About\n\nJenkins is the most popular Open Source Continuous Integration system. This Library will help you interact with Jenkins in a more developer-friendly way.\n\nThese are some of the features that are currently implemented:\n\n* Get information on test-results of completed/failed build\n* Ability to query Nodes, and manipulate them. Start, Stop, set Offline.\n* Ability to query Jobs, and manipulate them.\n* Get Plugins, Builds, Artifacts, Fingerprints\n* Validate Fingerprints of Artifacts\n* Create and Delete Users\n* Get Current Queue, Cancel Tasks\n* Create and Revoke API Tokens\n* etc. For all methods go to GoDoc Reference.\n\n## Installation\n\n    go get github.com/bndr/gojenkins\n\n## CLI\n\nFor users that would like CLI based on gojenkins, follow the steps below:\n\n   ```\n   $ cd cli/jenkinsctl\n   $ make\n   ```\n## Usage\n\n```go\n\nimport (\n  \"github.com/bndr/gojenkins\"\n  \"context\"\n  \"time\"\n  \"fmt\"\n)\n\nctx := context.Background()\njenkins := gojenkins.CreateJenkins(nil, \"http://localhost:8080/\", \"admin\", \"admin\")\n// Provide CA certificate if server is using self-signed certificate\n// caCert, _ := ioutil.ReadFile(\"/tmp/ca.crt\")\n// jenkins.Requester.CACert = caCert\n_, err := jenkins.Init(ctx)\n\n\nif err != nil {\n  panic(\"Something Went Wrong\")\n}\n\njob, err := jenkins.GetJob(ctx, \"#jobname\")\nif err != nil {\n  panic(err)\n}\nqueueid, err := job.InvokeSimple(ctx, params) // or  jenkins.BuildJob(ctx, \"#jobname\", params)\nif err != nil {\n  panic(err)\n}\nbuild, err := jenkins.GetBuildFromQueueID(ctx, job, queueid)\nif err != nil {\n  panic(err)\n}\n\n// Wait for build to finish\nfor build.IsRunning(ctx) {\n  time.Sleep(5000 * time.Millisecond)\n  build.Poll(ctx)\n}\n\nfmt.Printf(\"build number %d with result: %v\\n\", build.GetBuildNumber(), build.GetResult())\n\n```\n\nAPI Reference: https://godoc.org/github.com/bndr/gojenkins\n\n## Examples\n\nFor all of the examples below first create a jenkins object\n```go\nimport \"github.com/bndr/gojenkins\"\n\njenkins, _ := gojenkins.CreateJenkins(nil, \"http://localhost:8080/\", \"admin\", \"admin\").Init(ctx)\n```\n\nor if you don't need authentication:\n\n```go\njenkins, _ := gojenkins.CreateJenkins(nil, \"http://localhost:8080/\").Init(ctx)\n```\n\nyou can also specify your own `http.Client` (for instance, providing your own SSL configurations):\n\n```go\nclient := \u0026http.Client{ ... }\njenkins, := gojenkins.CreateJenkins(client, \"http://localhost:8080/\").Init(ctx)\n```\n\nBy default, `gojenkins` will use the `http.DefaultClient` if none is passed into the `CreateJenkins()`\nfunction.\n\n### Check Status of all nodes\n\n```go\nnodes := jenkins.GetAllNodes(ctx)\n\nfor _, node := range nodes {\n\n  // Fetch Node Data\n  node.Poll(ctx)\n\tif node.IsOnline(ctx) {\n\t\tfmt.Println(\"Node is Online\")\n\t}\n}\n\n```\n\n### Get all Builds for specific Job, and check their status\n\n```go\njobName := \"someJob\"\nbuilds, err := jenkins.GetAllBuildIds(ctx, jobName)\n\nif err != nil {\n  panic(err)\n}\n\nfor _, build := range builds {\n  buildId := build.Number\n  data, err := jenkins.GetBuild(ctx, jobName, buildId)\n\n  if err != nil {\n    panic(err)\n  }\n\n\tif \"SUCCESS\" == data.GetResult(ctx) {\n\t\tfmt.Println(\"This build succeeded\")\n\t}\n}\n\n// Get Last Successful/Failed/Stable Build for a Job\njob, err := jenkins.GetJob(ctx, \"someJob\")\n\nif err != nil {\n  panic(err)\n}\n\njob.GetLastSuccessfulBuild(ctx)\njob.GetLastStableBuild(ctx)\n\n```\n\n### Get Current Tasks in Queue, and the reason why they're in the queue\n\n```go\n\ntasks := jenkins.GetQueue(ctx)\n\nfor _, task := range tasks {\n\tfmt.Println(task.GetWhy(ctx))\n}\n\n```\n\n### Create View and add Jobs to it\n\n```go\n\nview, err := jenkins.CreateView(ctx, \"test_view\", gojenkins.LIST_VIEW)\n\nif err != nil {\n  panic(err)\n}\n\nstatus, err := view.AddJob(ctx, \"jobName\")\n\nif status != nil {\n  fmt.Println(\"Job has been added to view\")\n}\n\n```\n\n### Create nested Folders and create Jobs in them\n\n```go\n\n// Create parent folder\npFolder, err := jenkins.CreateFolder(ctx, \"parentFolder\")\nif err != nil {\n  panic(err)\n}\n\n// Create child folder in parent folder\ncFolder, err := jenkins.CreateFolder(ctx, \"childFolder\", pFolder.GetName())\nif err != nil {\n  panic(err)\n}\n\n// Create job in child folder\nconfigString := `\u003c?xml version='1.0' encoding='UTF-8'?\u003e\n\u003cproject\u003e\n  \u003cactions/\u003e\n  \u003cdescription\u003e\u003c/description\u003e\n  \u003ckeepDependencies\u003efalse\u003c/keepDependencies\u003e\n  \u003cproperties/\u003e\n  \u003cscm class=\"hudson.scm.NullSCM\"/\u003e\n  \u003ccanRoam\u003etrue\u003c/canRoam\u003e\n  \u003cdisabled\u003efalse\u003c/disabled\u003e\n  \u003cblockBuildWhenDownstreamBuilding\u003efalse\u003c/blockBuildWhenDownstreamBuilding\u003e\n  \u003cblockBuildWhenUpstreamBuilding\u003efalse\u003c/blockBuildWhenUpstreamBuilding\u003e\n  \u003ctriggers class=\"vector\"/\u003e\n  \u003cconcurrentBuild\u003efalse\u003c/concurrentBuild\u003e\n  \u003cbuilders/\u003e\n  \u003cpublishers/\u003e\n  \u003cbuildWrappers/\u003e\n\u003c/project\u003e`\n\njob, err := jenkins.CreateJobInFolder(ctx, configString, \"jobInFolder\", pFolder.GetName(), cFolder.GetName())\nif err != nil {\n  panic(err)\n}\n\nif job != nil {\n\tfmt.Println(\"Job has been created in child folder\")\n}\n\n```\n\n### Get All Artifacts for a Build and Save them to a folder\n\n```go\n\njob, _ := jenkins.GetJob(ctx, \"job\")\nbuild, _ := job.GetBuild(ctx, 1)\nartifacts := build.GetArtifacts(ctx)\n\nfor _, a := range artifacts {\n\ta.SaveToDir(\"/tmp\")\n}\n\n```\n\n### To always get fresh data use the .Poll() method\n\n```go\n\njob, _ := jenkins.GetJob(ctx, \"job\")\njob.Poll()\n\nbuild, _ := job.getBuild(ctx, 1)\nbuild.Poll()\n\n```\n\n### Create and Delete Users\n\n```go\n// Create user\nuser, err := jenkins.CreateUser(ctx, \"username\", \"password\", \"fullname\", \"user@email.com\")\nif err != nil {\n  log.Fatal(err)\n}\n// Delete User\nerr = user.Delete()\nif err != nil {\n  log.Fatal(err)\n}\n// Delete user not created by gojenkins\nerr = jenkins.DeleteUser(\"username\")\n```\n\n## Create and Revoke API Tokens\n\n```go\n// Create a token for admin user\ntoken, err := jenkins.GenerateAPIToken(ctx, \"TestToken\")\nif err != nil {\n  log.Fatal(err)\n}\n\n// Set Jenkins client to use new API token\njenkins.Requester.BasicAuth.Password = token.Value\n\n// Revoke token that was just created\ntoken.Revoke()\n\n// Revoke all tokens for admin user\nerr = jenkins.RevokeAllAPITokens(ctx)\nif err != nil {\n  log.Fatal(err)\n}\n```\n\n## Testing\n\n    go test\n\n## Contribute\n\nAll Contributions are welcome. The todo list is on the bottom of this README. Feel free to send a pull request.\n\n## TODO\n\nAlthough the basic features are implemented there are many optional features that are on the todo list.\n\n* Kerberos Authentication\n* Rewrite some (all?) iterators with channels\n\n## LICENSE\n\nApache License 2.0\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbndr%2Fgojenkins","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbndr%2Fgojenkins","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbndr%2Fgojenkins/lists"}