jenkinsjenkins-pipelineremote-serverbuild-triggers

How to know remote server ip in jenkins pipeline script?


I implemented jenkins build script. That script started by remote server. ( using Build Triggers )

In build console Output log, wrote down

"Started by remote host xx.xx.xxx.xxx (my ip)"

I want to know remote host that called jenkins build job in pipeline script.

Any ideas??

Thank you.


Solution

  • set an environment variable BUILD_CAUSES in your Jenkins pipeline script. Which will save all build information You can access it by jenkins file

    def remoteHost = ''
    for (cause in currentBuild.getCauses()) {
        if (cause instanceof Cause.RemoteCause) {
            remoteHost = cause.getAddr()
            break
        }
    }
    println "Remote host IP: ${remoteHost}"
    

    To set environment variable