[pipeline] approve input statement from another job with pipeline code

171 views
Skip to first unread message

Bill Dennis

unread,
Jun 7, 2017, 6:51:24 AM6/7/17
to Jenkins Users
(re-posting with corrections)

Has anyone managed to write pipeline code (or even their own plugin) to approve an input using pipeline code from another job (shared library NonCPS method or whatever)?

I have this scenario -

JobA

input id: 'JOBA_CALLBACK', message: 'Waiting for JobB', parameters: [string(defaultValue: '', description: 'ID of the callback', name: 'CALLBACK_ID')]


JobB

I want to write this with this hypothetical pipeline DSL which doesn't exist:

approveInput jobName:'JobA', buildNumber: 1234, , inputId: 'JOBA_CALLBACK', parameters: [CALLBACK_ID: '5678']

Job B in my scenario is actually called by an external system and can route to a couple of other jobs based on job parameters (so I cannot simply put Job B code into A).

CloudBees support recommended that I use a REST call-back onto Jenkins to do this (REST call onto Jenkins from JobB), 

I do have this and it works, the code looks like this using the HTTP Request plugin:

def REQUEST_URL = "${env.JENKINS_URL}/job/JobA/1234/wfapi/inputSubmit?inputId=JOBA_CALLBACK".toString()


def formJsonParamUrlEncoded = java.net.URLEncoder.encode("{\"parameter\":[{\"name\":\"CALLBACK_ID\",\"value\":5678]}").toString()


request
= httpRequest authentication: 'LOCAL_JENKINS',
 consoleLogResponseBody
: true,
 customHeaders
: [[name: 'content-type', value: 'application/x-www-form-urlencoded']],
 httpMode
: 'POST',
 requestBody
: "json=${formJsonParamUrlEncoded}",
 url
: REQUEST_URL,
 validResponseCodes
: '200'


echo
"Request returned: ${request.toString()}"

However this does introduce some failures into our system when our IT folks have outages that affect our authentication and such like (the REST call to Jenkins has authentication).

I would like to remove this possibility of failure hence looking at code to do it.

I feel that there ought to be a way to call Jenkins internals to do this, but probably it would be best to write a plugin that implements the hypothetical DSL I have.

If I did write a plugin, would others find this useful?

--Bill

Reply all
Reply to author
Forward
0 new messages