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

add create_folder method #55

Merged
merged 3 commits into from
Jun 26, 2017
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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