簡體   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