简体   繁体   English

Jenkins 2.x参数化触发器插件计算参数

[英]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.

相关问题 jenkins参数化触发器插件来触发另一个构建 - jenkins Parameterized Trigger Plugin to trigger another build 使用Jenkins参数化远程触发插件“with File参数上传到远程降级Jenkins作业 - Use Jenkins Parameterized Remote Trigger Plugin" with File parameter to upload to the remote downsteream Jenkins job Jenkins参数化触发器插件将值传递为“ VALUE” - Jenkins Parameterized Trigger Plugin passing value as “VALUE” Jenkins参数化触发器插件:按顺序启动脚本 - Jenkins parameterized trigger plugin : launch scripts in order 使用参数化触发器插件的Jenkins远程构建失败 - Jenkins remote build with Parameterized Trigger Plugin failed 无法使用jenkins参数化远程触发插件 - not able to use jenkins Parameterized Remote Trigger Plugin Jenkins:将参数从一个作业传递到另一个作业使用参数化触发器插件。 不工作 - Jenkins : Passing a parameter from one job to another used Parameterized Trigger Plugin. Not Working 将参数化的构建参数传递给Jenkins中的Jython插件 - Passing parameterized build parameter to Jython plugin in Jenkins 如何在 Jenkins Pipeline 脚本中使用“参数化远程触发器插件”? - How to use “Parameterized Remote Trigger Plugin” in Jenkins Pipeline script? 如何为jenkins参数化的远程触发器插件设置远程主机 - how to setup remote host for jenkins parameterized remote trigger plugin
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM