Permalink
Browse files

Add update and config commands.

  • Loading branch information...
1 parent 57f3826 commit 3836698759672ef853a437a3d9ecfb597cd6ad52 @cliffano committed Feb 13, 2014
Showing with 87 additions and 1 deletion.
  1. +1 −0 CHANGELOG.md
  2. +8 −0 README.md
  3. +20 −1 conf/commands.json
  4. +20 −0 lib/cli.js
  5. +36 −0 lib/jenkins.js
  6. +2 −0 test/cli.js
View
@@ -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
View
@@ -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>
@@ -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
View
@@ -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": {
@@ -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"
},
View
@@ -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) {
@@ -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) {
@@ -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 },
View
@@ -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) {
@@ -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.
View
@@ -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);

0 comments on commit 3836698

Please sign in to comment.