Skip to content

Commit

Permalink
Add update and config commands.
Browse files Browse the repository at this point in the history
  • Loading branch information
cliffano committed Feb 13, 2014
1 parent 57f3826 commit 3836698
Show file tree
Hide file tree
Showing 6 changed files with 87 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
### 0.2.3-pre
* Add enable and disable commands
* Add update and config commands

### 0.2.2
* Change test lib to buster-node + referee
Expand Down
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,10 @@ Create a new job with a specified config.xml:

nestor create <job> <path/to/config.xml>

Update an existing job with a specified config.xml:

nestor update <job> <path/to/config.xml>

Copy an existing job1 to a new job2:

nestor copy <job1> <job2>
Expand All @@ -83,6 +87,10 @@ Delete an existing job:

nestor delete <job>

Fetch the config.xml of an existing job:

nestor config <job>

View queued jobs:

nestor queue
Expand Down
21 changes: 20 additions & 1 deletion conf/commands.json
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,17 @@
{ "name": "config", "rules": [ "notEmpty" ] }
],
"examples": [
"nestor create job path/to/config.xml"
"nestor create <job> <path/to/config.xml>"
]
},
"update": {
"desc": "Update an existing job with a specified config.xml",
"args": [
{ "name": "job", "rules": [ "notEmpty" ] },
{ "name": "config", "rules": [ "notEmpty" ] }
],
"examples": [
"nestor update <job> <path/to/config.xml>"
]
},
"copy": {
Expand All @@ -103,6 +113,15 @@
"nestor delete job"
]
},
"config": {
"desc": "Fetch the config.xml of an existing job",
"args": [
{ "name": "job", "rules": [ "notEmpty" ] }
],
"examples": [
"nestor config <job>"
]
},
"queue": {
"desc": "View queued jobs"
},
Expand Down
20 changes: 20 additions & 0 deletions lib/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,15 @@ function _create(job, configFile, args) {
__exec(args, execCb);
}

function _update(job, configFile, args) {
function execCb(jenkins) {
jenkins.update(job, configFile, cli.exitCb(null, function (result) {
console.log(text.__('Job %s was updated successfully'), job);
}));
}
__exec(args, execCb);
}

function _copy(sourceJob, newJob, args) {
function execCb(jenkins) {
jenkins.copy(sourceJob, newJob, cli.exitCb(null, function (result) {
Expand All @@ -215,6 +224,15 @@ function _delete(job, args) {
__exec(args, execCb);
}

function _config(job, args) {
function execCb(jenkins) {
jenkins.config(job, cli.exitCb(null, function (result) {
console.log(result);
}));
}
__exec(args, execCb);
}

function _queue(args) {
function execCb(jenkins) {
jenkins.queue(cli.exitCb(null, function (result) {
Expand Down Expand Up @@ -312,8 +330,10 @@ function exec() {
enable: { action: _enable },
disable: { action: _disable },
create: { action: _create },
update: { action: _update },
copy: { action: _copy },
'delete': { action: _delete },
config: { action: _config },
queue: { action: _queue },
ver: { action: _version },
irc: { action: _irc },
Expand Down
36 changes: 36 additions & 0 deletions lib/jenkins.js
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,26 @@ Jenkins.prototype.create = function (jobName, configFile, cb) {
req.request('post', this.url + '/createItem/api/json', this.opts, cb);
};

Jenkins.prototype.update = function (jobName, configFile, cb) {

function _success(result, cb) {
cb();
}

this.opts.queryStrings = { name: jobName };
// this.opts.headers = { 'content-type': 'application/xml' };
this.opts.body = fs.readFileSync(configFile).toString();

function _notFound(result, cb) {
cb(new Error(text.__('Job %s does not exist', jobName)));
}

this.opts.handlers[200] = _success;
this.opts.handlers[404] = _notFound;

req.request('post', this.url + '/job/' + jobName + '/config.xml', this.opts, cb);
};

Jenkins.prototype.copy = function (sourceJobName, newJobName, cb) {

function _success(result, cb) {
Expand Down Expand Up @@ -478,6 +498,22 @@ Jenkins.prototype.delete = function (jobName, cb) {
req.request('post', this.url + '/job/' + jobName + '/doDelete', this.opts, cb);
};

Jenkins.prototype.config = function (jobName, cb) {

function _success(result, cb) {
cb(null, result.body);
}

function _notFound(result, cb) {
cb(new Error(text.__('Job %s does not exist', jobName)));
}

this.opts.handlers[200] = _success;
this.opts.handlers[404] = _notFound;

req.request('get', this.url + '/job/' + jobName + '/config.xml', this.opts, cb);
};

/**
* Retrieve jobs in the queue waiting for available executor or
* for a previously running build of the same job to finish.
Expand Down
2 changes: 2 additions & 0 deletions test/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,10 @@ buster.testCase('cli - exec', {
assert.defined(actions.commands.enable.action);
assert.defined(actions.commands.disable.action);
assert.defined(actions.commands.create.action);
assert.defined(actions.commands.update.action);
assert.defined(actions.commands.copy.action);
assert.defined(actions.commands['delete'].action);
assert.defined(actions.commands.config.action);
assert.defined(actions.commands.queue.action);
assert.defined(actions.commands.ver.action);
assert.defined(actions.commands.irc.action);
Expand Down

0 comments on commit 3836698

Please sign in to comment.