@@ -22,9 +22,9 @@ function ifBotWasMentionedInCiComment (commentBody, cb) {
2222
2323// URL to the Jenkins job should be triggered for a given repository
2424function buildUrlForRepo ( repo ) {
25- // e.g. JENKINS_JOB_URL_CITGM = https://ci.nodejs.org/job/citgm-continuous-integration- pipeline
25+ // e.g. JENKINS_JOB_URL_CITGM = https://ci.nodejs.org/blue/rest/organizations/jenkins/pipelines/node-test-pull-request-lite- pipeline/runs/
2626 const jobUrl = process . env [ `JENKINS_JOB_URL_${ repo . toUpperCase ( ) } ` ] || ''
27- return jobUrl ? ` ${ jobUrl } /build` : ''
27+ return jobUrl
2828}
2929
3030// Authentication token configured per Jenkins job needed when triggering a build,
@@ -41,26 +41,12 @@ function buildParametersForRepo (options, repo) {
4141 value : `refs/pull/${ options . number } /head`
4242 } ]
4343 } else {
44- return [ {
45- name : 'CERTIFY_SAFE' ,
46- value : 'true'
47- } ,
48- {
49- name : 'TARGET_GITHUB_ORG' ,
50- value : 'nodejs'
51- } ,
52- {
53- name : 'TARGET_REPO_NAME' ,
54- value : 'node'
55- } ,
56- {
57- name : 'PR_ID' ,
58- value : options . number
59- } ,
60- {
61- name : 'REBASE_ONTO' ,
62- value : '<pr base branch>'
63- }
44+ return [
45+ { name : 'CERTIFY_SAFE' , value : 'true' } ,
46+ { name : 'GITHUB_ORG' , value : 'nodejs' } ,
47+ { name : 'REPO_NAME' , value : 'node' } ,
48+ { name : 'PR_ID' , value : options . number } ,
49+ { name : 'REBASE_ONTO' , value : '' }
6450 ]
6551 }
6652}
@@ -70,7 +56,6 @@ function triggerBuild (options, cb) {
7056 const base64Credentials = new Buffer ( jenkinsApiCredentials ) . toString ( 'base64' )
7157 const authorization = `Basic ${ base64Credentials } `
7258
73- const payload = JSON . stringify ( { parameter : buildParametersForRepo ( options , repo ) } )
7459 const uri = buildUrlForRepo ( repo )
7560 const buildAuthToken = buildTokenForRepo ( repo )
7661
@@ -88,15 +73,15 @@ function triggerBuild (options, cb) {
8873 uri,
8974 headers : { authorization } ,
9075 qs : { token : buildAuthToken } ,
91- form : { json : payload }
76+ json : { parameters : buildParametersForRepo ( options , repo ) }
9277 } , ( err , response ) => {
9378 if ( err ) {
9479 return cb ( err )
95- } else if ( response . statusCode !== 201 ) {
96- return cb ( new Error ( `Expected 201 from Jenkins, got ${ response . statusCode } ` ) )
80+ } else if ( response . statusCode !== 200 ) {
81+ return cb ( new Error ( `Expected 200 from Jenkins, got ${ response . statusCode } ` ) )
9782 }
9883
99- cb ( null , response . headers . location )
84+ cb ( null , response . body . _links . self . href )
10085 } )
10186}
10287
@@ -163,20 +148,22 @@ module.exports = (app) => {
163148 logger
164149 }
165150
166- function logBuildStarted ( err ) {
151+ function replyToCollabWithBuildStarted ( err , buildUrl ) {
167152 if ( err ) {
168153 logger . error ( err , 'Error while triggering Jenkins build' )
169- } else {
170- logger . info ( 'Jenkins build started' )
154+ return createPrComment ( options , `@${ pullRequestAuthor } sadly an error occured when I tried to trigger a build :(` )
171155 }
156+
157+ createPrComment ( options , `@${ pullRequestAuthor } build started: https://ci.nodejs.org${ buildUrl } ` )
158+ logger . info ( { buildUrl } , 'Jenkins build started' )
172159 }
173160
174161 function triggerBuildWhenCollaborator ( err ) {
175162 if ( err ) {
176163 return logger . debug ( `Ignoring comment to me by @${ pullRequestAuthor } because they are not a repo collaborator` )
177164 }
178165
179- triggerBuild ( options , logBuildStarted )
166+ triggerBuild ( options , replyToCollabWithBuildStarted )
180167 }
181168
182169 githubClient . repos . checkCollaborator ( { owner, repo, username : pullRequestAuthor } , triggerBuildWhenCollaborator )
0 commit comments