Auto approve or dismiss input from pipeline script

199 views
Skip to first unread message

Raja Chinnam

unread,
Mar 21, 2017, 2:36:35 PM3/21/17
to Jenkins Users
Hello

I have a file input that pauses the build. The user may manually upload the file using the file input or make the file available on a network share. I am using the parallel construct to fork two branches - one for the input and one to look for the file on the share. Is there a way I can dismiss or approve the input if a file is found on the share?

I have tried a couple of ways but haven't had any luck so far.

I tried to approve/remove this input:
    input id: '1005', message: 'hello world', ok: 'ok', parameters: [string(defaultValue: 'ans', description: '', name: 'test')]



My first option:
def INPUT_URL = "${currentBuild.getAbsoluteUrl()}input/1005/submit"

def queryString = "name=test&value=ans&proceed=ok"

def conn = INPUT_URL.toURL().openConnection()

conn
.setRequestMethod("POST")
conn
.doOutput = true
def writer = new OutputStreamWriter(conn.outputStream)
writer
.write(queryString)
writer
.flush()
writer
.close()
conn
.connect()



This gives me a 403 forbidden.



My second option:
@NonCPS

def enumActions(){
   
def actionsList = currentBuild.rawBuild.getAllActions()
   
Action npt = null

   
for(Action acn : actionsList){
       
if(acn.getUrlName() == 'input') npt = acn

   
}
    currentBuild
.rawBuild.removeAction(npt)


   
//def npta = (org.jenkinsci.plugins.workflow.support.steps.input.InputAction)npt
   
//Is there a way to call approve methods on the above.
}



I have tried several things with this code and they mostly fail with NonSerializable exception.

Thank you
Raja

Baptiste Mathus

unread,
Mar 28, 2017, 4:39:57 PM3/28/17
to jenkins...@googlegroups.com
You'll need a specific script to read that share (a shell/powershell I mean, avoid using Jenkins API in Pipelines) before and handle this, independently of Jenkins (though you could also consider writing a plugin, depending on your use case).

Then if that script finds something, it'll be some simple if().



--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/adf671a8-7f92-496a-8557-978c1062805a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages