在Cloudbees Jenkins文件夹中设置环境变量

问题描述 投票:2回答:3

重新安装Jenkins和Cloudbees Free Enterprise插件后,我的Jenkins文件夹中设置的环境变量停止工作并从配置UI中消失。但是,它仍然存在于文件系统的config.xml中,如:

<properties>
 <com.cloudbees.hudson.plugins.folder.properties.EnvVarsFolderProperty>

我现在应该如何创建适用于整个文件夹的环境变量?

jenkins cloudbees
3个回答
3
投票

功能一直是moved到Folders Plus插件,这需要Jenkins Enterprise付费许可证。


0
投票

经过深思熟虑后,由于我不得不暂时处理这个需求,我已经做了一些工作来定义我自己的插件来满足这个需求。它允许您为文件夹定义一个String属性列表,然后由其中的作业继承,从而无需为文件夹内的所有作业反复指定相同的属性。

https://github.com/mig82/folder-properties-plugin

我希望这对其他人有用。一旦我有时间更好地记录它并编写一些测试脚本,我打算将它提交给Jenkins CI Org。


0
投票

@ Mig82提供了一个很好的解决方案。但是它有一个限制,即它提供的文件夹环境变量在自由式构建的SCM部分中不可用,并且可能在其他一些部分中。

我发现我可以使用一段groovy解决这个问题:

  1. 在自由式作业中,启用“为运行准备环境”部分。
  2. 在“为运行准备环境”部分中,将以下代码添加到“Evaluated Groovy Script”字段:

    import com.mig82.folders.wrappers.ParentFolderBuildWrapper
    import jenkins.tasks.SimpleBuildWrapper

    // Create a temporary Context object into which we can load the folder properties.
    myContext = new SimpleBuildWrapper.Context()

    // Create an object of the class "ParentFolderBuildWrapper".
    // This is the class at the heart of the Folder Properties plugin,
    // and it implements the code that gets the properties from the folder.
    parentFolderBuildWrapper = new ParentFolderBuildWrapper()

    // Load the folder properties into our Context object.
    parentFolderBuildWrapper.loadFolderProperties(currentJob, myContext)

    // Return the map containing the properties.
    return myContext.getEnv()

© www.soinside.com 2019 - 2024. All rights reserved.