@@ -34,7 +34,6 @@ Jenkins.prototype.lastBuildInfo = function (job, cb) {
3434 var errorMessages = {
3535 404 : 'Could not find a last build for job: ' + job
3636 } ;
37-
3837 return throwErrorBasedOnResponseCode ( res , errorMessages , cb ) ;
3938 }
4039
@@ -51,7 +50,6 @@ Jenkins.prototype.buildInfo = function (job, buildNumber, cb) {
5150 var errorMessages = {
5251 404 : 'Could not find build #' + buildNumber + ' for job: ' + job
5352 } ;
54-
5553 return throwErrorBasedOnResponseCode ( res , errorMessages , cb ) ;
5654 }
5755 cb ( null , body , res ) ;
@@ -67,7 +65,6 @@ Jenkins.prototype.jobInfo = function (job, cb) {
6765 var errorMessages = {
6866 404 : 'Could not find job: ' + job
6967 } ;
70-
7168 return throwErrorBasedOnResponseCode ( res , errorMessages , cb ) ;
7269 }
7370
@@ -84,7 +81,6 @@ Jenkins.prototype.buildOutput = function (job, buildNumber, cb) {
8481 var errorMessages = {
8582 404 : 'Could not find build #' + buildNumber + ' for job: ' + job
8683 } ;
87-
8884 return throwErrorBasedOnResponseCode ( res , errorMessages , cb ) ;
8985 }
9086
@@ -105,14 +101,31 @@ Jenkins.prototype.build = function (job, cb) {
105101 var errorMessages = {
106102 404 : 'Could not find job: ' + job
107103 } ;
108-
109104 return throwErrorBasedOnResponseCode ( res , errorMessages , cb ) ;
110105 }
111106
112107 var message = {
113108 message : 'Build triggered for job: ' + job
114109 } ;
110+ cb ( null , message , res ) ;
111+ } ) ;
112+ } ;
113+
114+ Jenkins . prototype . stopBuild = function ( job , buildNumber , cb ) {
115+ var url = baseUrl + '/job/' + job + '/' + buildNumber + '/stop' ;
116+ request . post ( url , function ( err , res ) {
117+ if ( err ) return cb ( err ) ;
115118
119+ if ( res . statusCode !== 200 && res . statusCode !== 302 ) {
120+ var errorMessages = {
121+ 404 : 'Could not find build #' + buildNumber + ' for job: ' + job
122+ } ;
123+ return throwErrorBasedOnResponseCode ( res , errorMessages , cb ) ;
124+ }
125+
126+ var message = {
127+ message : 'Requested to stop build #' + buildNumber + ' for job: ' + job
128+ } ;
116129 cb ( null , message , res ) ;
117130 } ) ;
118131} ;
@@ -126,7 +139,6 @@ Jenkins.prototype.jobList = function (cb) {
126139 var errorMessages = {
127140 404 : 'Could not find the job list for Jenkins server: ' + baseUrl
128141 } ;
129-
130142 return throwErrorBasedOnResponseCode ( res , errorMessages , cb ) ;
131143 }
132144
@@ -143,7 +155,6 @@ Jenkins.prototype.queue = function (cb) {
143155 var errorMessages = {
144156 404 : 'Could not find the build queue for Jenkins server: ' + baseUrl
145157 } ;
146-
147158 return throwErrorBasedOnResponseCode ( res , errorMessages , cb ) ;
148159 }
149160
0 commit comments