Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding suport to stop build api #29

Merged
merged 5 commits into from Apr 20, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
27 changes: 27 additions & 0 deletions .gitignore
@@ -0,0 +1,27 @@
# Logs
logs
*.log

# Runtime data
pids
*.pid
*.seed

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage

# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# node-waf configuration
.lock-wscript

# Compiled binary addons (http://nodejs.org/api/addons.html)
build/Release

# Dependency directory
# https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git-
node_modules
9 changes: 9 additions & 0 deletions README.md
Expand Up @@ -66,6 +66,15 @@ jenkins.build('job-in-jenkins', function(err, data) {
console.log(data)
});
```
### stop build

```javascript
jenkins.stop_build('job-in-jenkins', 'build-number',function(err, data) {
if (err){ return console.log(err); }
console.log(data)
});
```


### build with params

Expand Down
14 changes: 14 additions & 0 deletions lib/main.js
Expand Up @@ -8,6 +8,7 @@ var API = '/api/json';
var NEWJOB = '%s/createItem/?name=%s';
var DELETE = '%s/job/%s/doDelete';
var BUILD = '%s/job/%s/build' + API;
var STOP_BUILD = '%s/job/%s/%s/stop' + API;
var BUILD_INFO = '%s/job/%s/%s' + API;
var DISABLE = '%s/job/%s/disable';
var ENABLE = '%s/job/%s/enable';
Expand Down Expand Up @@ -78,6 +79,19 @@ var init = exports.init = function(host, options) {
callback(null, data);
});
},
stop_build: function(jobname, buildNumber, callback) {
var buildurl;
buildurl = build_url(STOP_BUILD, jobname, buildNumber);

request({method: 'POST', url: buildurl }, function(error, response) {
if ( error || (response.statusCode !== 201 && response.statusCode !== 302) ) {
callback(error, response);
return;
}
var data = "job is stopped";
callback(null, data);
});
},
all_jobs: function(callback) {
/*
Return a list of object literals containing the name and color of all jobs on the Jenkins server
Expand Down