繁体   English   中英

获取可用于 jenkins 作业的所有托管文件

[英]Get all managed files available for jenkins job

我已经在 Jenkins 的托管文件部分中以 JSON 格式存储了一些作业的配置,并且它按预期工作。 我想通过将这些作业更改为参数化作业来扩展它,其中所有可用的托管文件(不是全局文件)都可以从组合框中选择,但我在获取所有可用的托管文件时遇到问题。 像 configFileProvider 这样的插件能够同时获得全局的和更多的工作空间/命名空间特定的,所以我认为会有一种简单的方法来实现这一点。

添加更多特定于作业的非全局配置文件

1

def files = org.jenkinsci.plugins.configfiles.GlobalConfigFiles.get().getConfigs()

适用于全局的,但我想获得工作区/命名空间特定的,并认为它会像这样 go

def files = org.jenkinsci.plugins.configfiles.getConfigsInContext()

如果有人能指出我如何实现这一目标的正确方向,那就太棒了。

谢谢

我不知道任何直接的解决方案来实现它,因为这些托管文件没有作为文件存储在磁盘中。

我实现它的方法是运行一个脚本来解析 ${jenkins_home}/org.jenkinsci.plugins.configfiles.GlobalConfigFiles.xml 文件并在磁盘中创建托管文件。

将这些文件放在磁盘中,您可以使用“文件系统列表参数插件”将它们列在作业参数中。

这样你

作业参数

托管文件

参数设置

脚本

#!/bin/bash

filenames=$(xmllint --xpath '//name/text()' GlobalConfigFiles.xml 2>/dev/null)

while read -r filename
do 

content=$(xmllint --xpath "//name[text()='$filename']/../content/text()" GlobalConfigFiles.xml 2>/dev/null)

if [[ "$filename" == *"xml"* ]]; then
    echo $content | sed -nr 's/&lt;/</gp' | sed -nr 's/&gt;/>/gp' > $filename
else
    echo $content > $filename
fi
done <<< $filenames

检查以下脚本

// name of the folde you want get configfiles from
def folderName = "Folder2" 
def folderItem = Jenkins.instance.getAllItems(com.cloudbees.hudson.plugins.folder.AbstractFolder.class).find{ (it.name == folderName) }

// If you want to filter a specific configFile type, example Json configs here
def descriptor =  org.jenkinsci.plugins.configfiles.json.JsonConfig.JsonConfigProvider.class 

def allConfigFiles = folderItem.getProperties().get(org.jenkinsci.plugins.configfiles.folder.FolderConfigFileProperty.class).getConfigs();

def jonConfigFiles = folderItem.getProperties().get(org.jenkinsci.plugins.configfiles.folder.FolderConfigFileProperty.class).getConfigs(descriptor);
            
echo "$allConfigFiles"
echo "$jonConfigFiles"

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM