Inject variable in pipeline plugin

105 views
Skip to first unread message

Andreas Wuz

unread,
Dec 27, 2016, 7:45:56 AM12/27/16
to Jenkins Users
Hi @ all,

I have a pipeline job in jenkins 2.36, which can be triggered by a remote http-call. Now I have to inject the ip-address of the calling client. In a normal job I did this with the EnvInject-Plugin with following script:
import hudson.model.*
import static hudson.model.Cause.RemoteCause


def ipaddress=""
for (CauseAction action : currentBuild.getActions(CauseAction.class)) {

   
for (Cause cause : action.getCauses()) {
       
if(cause instanceof RemoteCause){
             ipaddress
=cause.addr
             
break;
       
}
   
}
}
return ["ip":ipaddress]

But how can I achieve this with the pipeline-plugin? I cannot use the EnvInject-Plugin in this :-(

Oleg Nenashev

unread,
Dec 27, 2016, 11:01:59 AM12/27/16
to Jenkins Users
there is a withEnv() wrapper, see https://github.com/jenkinsci/pipeline-plugin/blob/master/TUTORIAL.md#managing-the-environment. In order to use it in Pipeline with a similar code, you will likely need to allow several binary API calls in script security. Not sur eif it's convenient

BR, Oleg

вторник, 27 декабря 2016 г., 13:45:56 UTC+1 пользователь Andreas Wuz написал:

Andreas Wuz

unread,
Dec 30, 2016, 5:23:33 AM12/30/16
to Jenkins Users
Hi, thanks for your answer :)

But how can I inject this variable? Is it like this:

withEnv(["ip"]) { //Script for getting the ip }
Sorry I'm a newby in Jenkins and Groovy. How can I set the scrpit security for allow binary API calls?
Reply all
Reply to author
Forward
0 new messages