通过REST API调用从成功的jenkins作业中检索自定义变量 [英] Retrieve custom variable from a successful jenkins job run via REST api call

查看:246
本文介绍了通过REST API调用从成功的jenkins作业中检索自定义变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从成功的上一次稳定构建jenkins作业中检索自定义变量.我可以使用Execute Shell在此链接上使用curl来检索内部版本号.这是一台内部服务器. https://jenkinsci.internalsvr/view/webapps/job/common-tools /lastStableBuild/buildNumber

I would like to retrieve a custom variable from a successful last stable build jenkins job. I was able to retrieve the build number using curl on this link using Execute Shell. It's an internal server. https://jenkinsci.internalsvr/view/webapps/job/common-tools/lastStableBuild/buildNumber

现在,我想对使用curl的自定义变量执行相同的操作.但是我知道我可能需要保存自定义变量的值,但不确定如何以及在何处.

Now, I'd like to do the same for a custom variable using curl. But I know that I may need to save the value of the custom variable but not sure how and to where.

推荐答案

这就是我的工作方式

我的dsl.groovy文件中有此代码

I have this code in our dsl.groovy file

....

parameters {
    stringParam('CUSTOM_VAR1', '', 'Custom Variable')
    stringParam('CUSTOM_VAR2', '', 'Custom Variable')
}

shellCommands = sprintf('''#/bin/bash
echo "CUSTOM_VAR1=\${%s}" > env.properties
echo "CUSTOM_VAR2=\${%s}" >> env.properties
''', ['CUSTOM_VARIABLE1','CUSTOM_VARIABLE1'])

shell(shellCommands)

// This is extremely important
environmentVariables {
  propertiesFile('env.properties')
}

// This allowed me to retrieve env.properties via http call from browser or curl.

publishers {
  archiveArtifacts {
    pattern('env.properties')
  }
}

因此,如果我需要访问它,则http网址应采用这样的格式

So if I need to access it, the http url should be formed like this

curl https://our-internal-server/job/theNameOfTheJob/lastStableBuild/artifact/env.properties

这篇关于通过REST API调用从成功的jenkins作业中检索自定义变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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