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.
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
click on the job where you want to set the variable from homepage.
Go to "Configure" link for your job.
Go to "Build Environment" section.
Check the "Set environment variables" checkbox.
In the "Name" field, enter "BUILD_CAUSES".
In the "Value" field, enter the desired value for the BUILD_CAUSES variable.
Click the "Save" button to save your changes.