将客户端IP信息传递给Jenkins Job [英] Passing client IP information to Jenkins Job

查看:191
本文介绍了将客户端IP信息传递给Jenkins Job的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Jenkins中,我想将启动构建的客户端的ip传递给Jenkins作业,以便我可以在扩展"Builder"的类中或作为环境变量或任何有效方法访问该信息.

In Jenkins, I want to pass the ip of the client that initiated the build to the Jenkins job so I can access that information inside a class that extends "Builder" or as an environment variable, or anything that works.

因此,例如,在每个版本的控制台日志中,我可以打印以下内容:由user1从ip启动的作业:10.101.101.1"

So for example, in the console log of every build, I can print something like: "Job started by user1 from ip: 10.101.101.1"

我知道我可以通过使用针对Jenkins的审核试用"插件来进行审计试用,但是我想将这些信息打印到构建控制台,这样会更加直接.

I know I can get an audit trial by using the "Audit Trial" plugin for Jenkins, but I would like to print that information to the build console so it'll be more straight forward.

先谢谢了.

我想要启动作业/构建的用户/客户端的ip,这不一定是作业正在运行的jenkins从属服务器的ip.

I want the ip of the user/client that started the job/build, which is not necessarily the ip of the jenkins slave the job is running on.

推荐答案

Jenkins目前无法将客户端IP传递给变量,您在输出日志中看到的客户端IP是远程原因消息.

Jenkins not able to pass the client IP to a variable at the moment , the Client IP you saw at the output log is remote cause message.

我要说的是,在工作中获取远程IP以启用某些回调功能确实有用.或者,您可以在进行远程呼叫时将IP作为参数传递

I would say it is indeed useful to get remote IP in a job to enable some callback functions . Alternatively you can pass the IP as parameter when make the remote call

  1. 在jenkins job的shell脚本中回显$ ipaddr

  1. echo $ipaddr in your shell script of jenkins job

在jenkins作业中启用字符串参数 https://wiki.jenkins-ci.org/display/JENKINS/Parameterized+Build

Enable the string parameters in jenkins job https://wiki.jenkins-ci.org/display/JENKINS/Parameterized+Build

拨打电话

curl -k -u用户:apitoken -X POST https://jenkins.local/job/yourjob/build \ --data token = jobtoken \
--data-urlencode json ='{参数":[{名称":"ipaddr",值":"x.x.x.x"}]}''

curl -k -u user:apitoken -X POST https://jenkins.local/job/yourjob/build \ --data token=jobtoken \
--data-urlencode json='{"parameter": [{"name":"ipaddr", "value":"x.x.x.x"}]}'

这篇关于将客户端IP信息传递给Jenkins Job的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆