Skip to content

Commit

Permalink
Merge pull request #55 from ondrejchmelar/master
Browse files Browse the repository at this point in the history
add create_folder method
  • Loading branch information
kub1x committed Jun 26, 2017
2 parents 5453136 + 1deccd2 commit d04989f
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,7 @@ build/Release

# Dependency directory
# https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git-
node_modules
node_modules

# IDEs
.idea/
29 changes: 28 additions & 1 deletion lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ var util = require('util')

var API = '/api/json';
var NEWJOB = '%s/createItem/?name=%s';
var NEWFOLDER = '%s/createItem/?name=%s&mode=%s&Submit=OK';
var DELETE = '%s/job/%s/doDelete';
var BUILD = '%s/job/%s/build' + API;
var STOP_BUILD = '%s/job/%s/%s/stop' + API;
Expand Down Expand Up @@ -433,6 +434,33 @@ var init = exports.init = function(host, options) {
});
});
},
create_folder: function(foldername, callback) {
/*
Create a new folder
Needs Folder plugin in Jenkins: https://wiki.jenkins-ci.org/display/JENKINS/CloudBees+Folders+Plugin
curl -XPOST 'http://jenkins/createItem?name=FolderName&mode=com.cloudbees.hudson.plugins.folder.Folder&from=&json=%7B%22name%22%3A%22FolderName%22%2C%22mode%22%3A%22com.cloudbees.hudson.plugins.folder.Folder%22%2C%22from%22%3A%22%22%2C%22Submit%22%3A%22OK%22%7D&Submit=OK' --user user.name:YourAPIToken -H "Content-Type:application/x-www-form-urlencoded"
https://gist.github.com/stuart-warren/7786892
*/

var mode = 'com.cloudbees.hudson.plugins.folder.Folder';
request(
{method: 'POST'
,url: build_url(NEWFOLDER, foldername, mode)
,headers: { "content-type": "application/x-www-form-urlencoded"}
},

function(error, response, body) {
if ( error || response.statusCode !== 200 ) {
callback(error || true, response);
return;
}
var data = body;
callback(null, data);
}
);
},
update_config: function(jobname, modifyfunction, callback) {
/* Update a job config and allows you to pass in a function to modify the configuration
of the job you would like to update */
Expand All @@ -451,7 +479,6 @@ var init = exports.init = function(host, options) {
callback(null, data);
});
});

},
update_job: function(jobname, job_config, callback) {
/* Update a existing job based on a job_config string */
Expand Down

0 comments on commit d04989f

Please sign in to comment.