[英]Jenkins 2.x Parameterized Trigger Plugin Computed Parameter
I am using the above plugin in a Jenkins job, but want to pass the invoked job some parameter that is computed and/or fetched from some custom source. 我在Jenkins作业中使用上面的插件,但想传递调用的作业某些参数,这些参数是从某些自定义来源计算和/或获取的。 Easy enough to do in a shell script, except that none of the Add Parameters options that are built-in allow for a way to do this kind of dynamic computation.
在shell脚本中很容易做到,除了内置的“添加参数”选项均不允许使用这种方式进行这种动态计算。
I have found the EnvInject plugin, but the problem here is that the computed parameter is a secret and needs to avoid being stored anywhere on disk. 我找到了EnvInject插件,但是这里的问题是计算出的参数是秘密的,需要避免将其存储在磁盘上的任何位置。 The only way I could figure out in the EnvInject plugin requires first writing the computed secret to disk and then read it in from that disk file as an environment variable in a subsequent step using the EnvInject plugin.
我可以在EnvInject插件中找出的唯一方法是,首先将计算出的密钥写入磁盘,然后在随后的步骤中使用EnvInject插件从该磁盘文件中将其作为环境变量读取。
So the question is, is there any known parameter source for the Parameterized Trigger Plugin (docs says the parameter sources themselves are pluggable) that would allow me to compute the parameter dynamically? 所以问题是,是否存在用于Parameterized Trigger Plugin的任何已知参数源(文档称参数源本身是可插入的)可以使我动态地计算参数?
So I found that the EnvInject plugin can inject environment variables from evaluating a Groovy script. 因此,我发现EnvInject插件可以通过评估Groovy脚本来注入环境变量。 A little less convenient than a simple shell script, especially as there aren't that many examples to be found online or in the plugin docs, but it works.
比简单的shell脚本要方便一些,特别是因为在网上或插件文档中找不到很多示例,但是它可以工作。
An example script, which you can put in the Build Environment section by checking the "Inject environment variables" checkbox: 一个示例脚本,可以通过选中“注入环境变量”复选框将其放置在“构建环境”部分中:
try {
def json = /curl -s -H "X-Vault-Token:${VAULT_TOKEN}" -X GET https://xxx.yyy.zzz/v1/secret/oe/dmp/aws/mykey.key/.execute().text
def access_key_id = /echo '${json}' | jq -r '.data' | jq -r '.aws_access_key_id'/.execute().text>
def secret_access_key = /echo '${json}' | jq -r '.data' | jq -r '.aws_secret_access_key'/.execute().text
return ['AWS_SECRET_ACCESS_KEY' : secret_access_key, 'AWS_ACCESS_KEY_ID' : access_key_id]
} catch (Throwable t) {
println(t)
throw t;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.