Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add enable and disable commands.

  • Loading branch information...
commit 57f382653c7d0ccd4792c657bf70dc038ffdb1fc 1 parent 39aa462
@cliffano authored
View
2  CHANGELOG.md
@@ -1,5 +1,5 @@
### 0.2.3-pre
-*
+* Add enable and disable commands
### 0.2.2
* Change test lib to buster-node + referee
View
14 README.md
@@ -63,17 +63,25 @@ View job status reports:
nestor job <job>
+Enable a job:
+
+ nestor enable <job>
+
+Disable a job:
+
+ nestor disable <job>
+
Create a new job with a specified config.xml:
- nestor create path/to/config.xml
+ nestor create <job> <path/to/config.xml>
Copy an existing job1 to a new job2:
- nestor copy job1 job2
+ nestor copy <job1> <job2>
Delete an existing job:
- nestor delete job
+ nestor delete <job>
View queued jobs:
View
18 conf/commands.json
@@ -56,6 +56,24 @@
{ "name": "job", "rules": [ "notEmpty" ] }
]
},
+ "enable": {
+ "desc": "Enable a job",
+ "args": [
+ { "name": "job", "rules": [ "notEmpty" ] }
+ ],
+ "examples": [
+ "nestor enable job"
+ ]
+ },
+ "disable": {
+ "desc": "Disable a job",
+ "args": [
+ { "name": "job", "rules": [ "notEmpty" ] }
+ ],
+ "examples": [
+ "nestor disable job"
+ ]
+ },
"create": {
"desc": "Create a new job with a specified config.xml",
"args": [
View
20 lib/cli.js
@@ -170,6 +170,24 @@ function _job(name, args) {
__exec(args, execCb);
}
+function _enable(job, configFile, args) {
+ function execCb(jenkins) {
+ jenkins.enable(job, cli.exitCb(null, function (result) {
+ console.log(text.__('Job %s was enabled successfully'), job);
+ }));
+ }
+ __exec(args, execCb);
+}
+
+function _disable(job, configFile, args) {
+ function execCb(jenkins) {
+ jenkins.disable(job, cli.exitCb(null, function (result) {
+ console.log(text.__('Job %s was disabled successfully'), job);
+ }));
+ }
+ __exec(args, execCb);
+}
+
function _create(job, configFile, args) {
function execCb(jenkins) {
jenkins.create(job, configFile, cli.exitCb(null, function (result) {
@@ -291,6 +309,8 @@ function exec() {
discover: { action: _discover },
executor: { action: _executor },
job: { action: _job },
+ enable: { action: _enable },
+ disable: { action: _disable },
create: { action: _create },
copy: { action: _copy },
'delete': { action: _delete },
View
36 lib/jenkins.js
@@ -377,6 +377,42 @@ Jenkins.prototype.job = function (name, cb) {
req.request('get', this.url + '/job/' + name + '/api/json', this.opts, cb);
};
+Jenkins.prototype.enable = function (jobName, cb) {
+
+ var self = this;
+
+ function _success(result, cb) {
+ cb();
+ }
+
+ 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 + '/enable', this.opts, cb);
+};
+
+Jenkins.prototype.disable = function (jobName, cb) {
+
+ var self = this;
+
+ function _success(result, cb) {
+ cb();
+ }
+
+ 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 + '/disable', this.opts, cb);
+};
+
Jenkins.prototype.create = function (jobName, configFile, cb) {
function _success(result, cb) {
View
5 test/cli.js
@@ -26,6 +26,11 @@ buster.testCase('cli - exec', {
assert.defined(actions.commands.discover.action);
assert.defined(actions.commands.executor.action);
assert.defined(actions.commands.job.action);
+ assert.defined(actions.commands.enable.action);
+ assert.defined(actions.commands.disable.action);
+ assert.defined(actions.commands.create.action);
+ assert.defined(actions.commands.copy.action);
+ assert.defined(actions.commands['delete'].action);
assert.defined(actions.commands.queue.action);
assert.defined(actions.commands.ver.action);
assert.defined(actions.commands.irc.action);
Please sign in to comment.
Something went wrong with that request. Please try again.