@@ -22,9 +22,9 @@ function ifBotWasMentionedInCiComment (commentBody, cb) {
22
22
23
23
// URL to the Jenkins job should be triggered for a given repository
24
24
function 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/
26
26
const jobUrl = process . env [ `JENKINS_JOB_URL_${ repo . toUpperCase ( ) } ` ] || ''
27
- return jobUrl ? ` ${ jobUrl } /build` : ''
27
+ return jobUrl
28
28
}
29
29
30
30
// Authentication token configured per Jenkins job needed when triggering a build,
@@ -41,26 +41,12 @@ function buildParametersForRepo (options, repo) {
41
41
value : `refs/pull/${ options . number } /head`
42
42
} ]
43
43
} 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 : '' }
64
50
]
65
51
}
66
52
}
@@ -70,7 +56,6 @@ function triggerBuild (options, cb) {
70
56
const base64Credentials = new Buffer ( jenkinsApiCredentials ) . toString ( 'base64' )
71
57
const authorization = `Basic ${ base64Credentials } `
72
58
73
- const payload = JSON . stringify ( { parameter : buildParametersForRepo ( options , repo ) } )
74
59
const uri = buildUrlForRepo ( repo )
75
60
const buildAuthToken = buildTokenForRepo ( repo )
76
61
@@ -88,15 +73,15 @@ function triggerBuild (options, cb) {
88
73
uri,
89
74
headers : { authorization } ,
90
75
qs : { token : buildAuthToken } ,
91
- form : { json : payload }
76
+ json : { parameters : buildParametersForRepo ( options , repo ) }
92
77
} , ( err , response ) => {
93
78
if ( err ) {
94
79
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 } ` ) )
97
82
}
98
83
99
- cb ( null , response . headers . location )
84
+ cb ( null , response . body . _links . self . href )
100
85
} )
101
86
}
102
87
@@ -163,20 +148,22 @@ module.exports = (app) => {
163
148
logger
164
149
}
165
150
166
- function logBuildStarted ( err ) {
151
+ function replyToCollabWithBuildStarted ( err , buildUrl ) {
167
152
if ( err ) {
168
153
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 :(` )
171
155
}
156
+
157
+ createPrComment ( options , `@${ pullRequestAuthor } build started: https://ci.nodejs.org${ buildUrl } ` )
158
+ logger . info ( { buildUrl } , 'Jenkins build started' )
172
159
}
173
160
174
161
function triggerBuildWhenCollaborator ( err ) {
175
162
if ( err ) {
176
163
return logger . debug ( `Ignoring comment to me by @${ pullRequestAuthor } because they are not a repo collaborator` )
177
164
}
178
165
179
- triggerBuild ( options , logBuildStarted )
166
+ triggerBuild ( options , replyToCollabWithBuildStarted )
180
167
}
181
168
182
169
githubClient . repos . checkCollaborator ( { owner, repo, username : pullRequestAuthor } , triggerBuildWhenCollaborator )
0 commit comments