yosida95 / golang-jenkins Goto Github PK
View Code? Open in Web Editor NEWAPI client of Jenkins API written in Go
Home Page: http://godoc.org/github.com/yosida95/golang-jenkins
License: MIT License
API client of Jenkins API written in Go
Home Page: http://godoc.org/github.com/yosida95/golang-jenkins
License: MIT License
nice work on golang-jenkins BTW!
we've a need to parse the new pipeline jobs from Jenkins 2.x; so a PR is on its way to add a wrapper type above MavenJobItem to be able to parse maven or pipeline jobs
The 2.x API is a bit differen than the 1.x, also is an annoying thing with the Parameterized build vs. non parameterized build.
/job/FolderA/job/JobB
Not sure why we really need to detect if the build has parameters or not. There is an option to pass paramets to the Build
function for example. If we pass parameters, the build is parameterized. If not, it's not parameterized. So this might be enough to check and don't need to parse the Job JSON for parameterDefiniton
"somewhere". It can change time to time so better not to rely on it.
Before every POST, the code should check the /crumbIssuer/api/json
and get the current crumb and field name. Otherwise you'll get error like no valid crumb...
. The CSRF should be always turned on due to security reasons.
The implementation PoC looks like below, pretty easy. If the CSRF is not enabled, you'll get a 404 on the /crumbIssuer, so actually it just will leave the Crumb/CrumbRequestField an empty string so easy to check/handle.
type CrumbIssuer struct {
Crumb string `json:"crumb"`
CrumbRequestField string `json:"crumbRequestField"`
}
...
// getCrumb returns a csrf crumb for post.
func (jenkins *Jenkins) getCrumb() (CrumbIssuer, error) {
payload := CrumbIssuer{}
err := jenkins.get("/crumbIssuer", nil, &payload)
return payload, err
}
Another issue is that the Build()
function uses the job.Name
and not the job.Url
for the post, so it generates a wrong URL for a job. The job.Url
would be a better approach, so relying on the job URL provided by jenkins itself.
job := jenkins.GetJob('folderA/job/JobB')
// this will successfully populate the the job.
// job.Name will be JobB which will cause a 404 on this post.
jenkins.post(fmt.Sprintf("/job/%s/buildWithParameters", job.Name), params, nil)
At present, a Jenkins
object has a single Requester
, and context (headers, "api/json" suffix, etc.) is cached in the singleton Requester
for the duration of a request/response. This means that any kind of data mining (getting the SCM data for each job, say) must be done one-at-a-time.
Hey,
can you add gitter chat to this repo,so that contributors can talk ?
Parameters and their values are retrieved via jenkins.GetJob()
but the response body is not is not pulled into the Action
struct slice.
I have left the Value
as interface{}
as it is sent over as a mixed type.
I did consider adding something to simplify the casting but it seems overkill.
When calling GetBuild()
, the error returned can be this:
invalid character '<' looking for beginning of value
This is an error from the encoding/json
package produced when trying to decode the response to /job/name/number
. If the job doesn't exist, the 404 response from Jenkins unfortunately has a HTML body, not a JSON body.
I'd like to change the code so that this error is caught by checking the response body and replacing it with something like ErrJobNotFound
, so that my calling code can handle this more cleanly.
This actually happens quite often, as I often try to submit a job then immediately get its status, and Jenkins sends a 404 when the job is still queued.
The code for this is trivial, but I thought I'd put this in as an issue to get any feedback before I put in a PR.
When I call Build() my Job in jenkins runs but I never get the results of that build as it retuns as soon as jenkins has recieved the request. Can you tell me how I would get the status for that build (which I do not even get a build number from the Build() request? Thanks!
According to https://wiki.jenkins.io/display/JENKINS/Remote+access+API, file upload is possible, but it's not apparent how to do this with the current interface (Build takes url.Values).
When I get jenkins some build status(or information), but has no change logs in Build
struct.
So I will add related structures.
Hi,
what if user wanted test result of last build,I think its better to add api's which will just return json with last successful run test cases,failed and skipped one.For sake of simplicity at this moment you can just consider maven-junit test report which provides there own rest-api to get numbers.I have did that in one of my go project.
Specific scenario is to allow ignoring expired SSL certificates but this also allows for additional scenarios with custom timeout values.
tr := &http.Transport{
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
}
client := &http.Client{
Transport: tr,
Timeout: time.Duration(2 * time.Second),
}
jenkins.EnhanceClient(client)
Hi there,
This should require an enhancement to jenkins.go.
When I request a pipeline jenkins job (with parameters), there's no any "actions" has ParameterDefinitions returned.
So when the process goes to below function, it always returns false.
// hasParams returns a boolean value indicating if the job is parameterized func hasParams(job Job) bool { for _, action := range job.Actions { if len(action.ParameterDefinitions) > 0 { return true } } return false }
I just found the difference of the way Jenkins API indicates parameter property of a job between freestyle project and pipeline:
with freestyle project,the parameter property is wrapped in "actions":
"actions": [ { "_class": "hudson.model.ParametersDefinitionProperty", "parameterDefinitions": [ { "_class": "hudson.model.ChoiceParameterDefinition", "defaultParameterValue": { "_class": "hudson.model.StringParameterValue", "value": "app" }, "description": "", "name": "app", "type": "ChoiceParameterDefinition", "choices": [ "print-app", "idm-app", "file-app" ] } ] }, {}, {}, {}, {}, {}, { "_class": "com.cloudbees.plugins.credentials.ViewCredentialsAction" } ],
with pipeline , the parameter property is wrapped in "property":
"property": [ { "_class": "hudson.model.ParametersDefinitionProperty", "parameterDefinitions": [ { "_class": "com.cwctravel.hudson.plugins.extended_choice_parameter.ExtendedChoiceParameterDefinition", "defaultParameterValue": null, "description": "", "name": "Jar_to_Publish", "type": "PT_CHECKBOX" } ] } ],
i have jenkins server with multiple projects folders. and all the jobs are hosted inside this sub-folder.
now this api trigger the pipeline with job name as 'only job name' and url device with full path including this project folder. however it is not getting the build from jenkins with this way. if i include the path in job variable and leave url is base url. it can rigger and get build number but can not get its status of pass/fail
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.