如何根据作业参数设置Jenkins环境变量? [英] How do I set a Jenkins environment variable based on a job parameter?

查看:407
本文介绍了如何根据作业参数设置Jenkins环境变量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个项目,需要根据用户选择的选择参数设置环境变量.每个项目都有一个主题项目依赖项.我想让用户选择项目,然后从属性文件中加载主题名称.像

I have a project where I need to set an environment variable based on a choice parameter the user chooses. Each project has a theme project dependency. I'd like to have the user choose the project and then load the theme name from a property file. Something like

proj1=theme1
proj2=theme2
proj3=theme3

如果用户从PROJECT_NAME选择参数中选择proj1,我想自动将THEME_NAME设置为theme1.最好的方法是什么?

If the user chooses proj1 from the PROJECT_NAME choice parameter, I want to automatically set THEME_NAME to be theme1. What would be the best way to go about this?

无论何时添加新项目,我都不想修改Jenkins作业配置.相反,我希望将映射包含在文件中,以便可以在版本控制中使用它.

I don't want to modify the Jenkins job config whenever a new project is added. Instead, I want to have the mapping in a file so I can have it in version control.

推荐答案

哈哈,我找到了一个简单的解决方案!在工作配置中使用EnvInject插件:

Aha, I found a simple solution! Using the EnvInject plugin, in the job config:

构建环境

[X]在构建过程中注入环境变量

[X] Inject environment variables to the build process

属性文件路径C:\pathtofile\mapping.properties

属性内容THEME_NAME=${${PROJECT_NAME}}

像魅力一样工作!

这篇关于如何根据作业参数设置Jenkins环境变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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