我在Jenkins中安裝了活動選項參數。在這裏,我必須從本地存儲的文本文件中選擇一個值,然後將其顯示爲用戶的多選選項。 例如,我的文本文件可以有一個條目1 - abc,2 - def。用戶必須看到兩個條目,並且可以選擇其中的一個或兩個。這個文本文件是手動維護的。我可以有第三項3-ghi,當我觸發詹金斯的工作時,我應該看到所有3項。活躍選擇參數
任何人都可以請幫我一下嗎?
謝謝你在前進, 羅希特
我在Jenkins中安裝了活動選項參數。在這裏,我必須從本地存儲的文本文件中選擇一個值,然後將其顯示爲用戶的多選選項。 例如,我的文本文件可以有一個條目1 - abc,2 - def。用戶必須看到兩個條目,並且可以選擇其中的一個或兩個。這個文本文件是手動維護的。我可以有第三項3-ghi,當我觸發詹金斯的工作時,我應該看到所有3項。活躍選擇參數
任何人都可以請幫我一下嗎?
謝謝你在前進, 羅希特
您可以使用Groovy腳本解析文件和恢復選項,類似:
def list = []
File textfile= new File("path-to-file")
textfile.eachline { line ->
//assuming you want only text values without a number
list.add(line.split('-')[1]) }
return list
也可以選擇「選擇型」爲多個值。
試試這個:
// create blank array/list to hold choice options for this parameter and also define any other variables.
def list = []
def file = "/opt/data/jenkins/jobs/dummy_dummy/workspace/somefile.txt"
// create a file handle named as textfile
File textfile= new File(file)
// now read each line from the file (using the file handle we created above)
textfile.eachLine { line ->
//add the entry to a list variable which we'll return at the end.
//The following will take care of any values which will have
//multiple '-' characters in the VALUE part
list.add(line.split('-')[1..-1].join(',').replaceAll(',','-'))
}
//Just fyi - return will work here, print/println will not work inside active choice groovy script/scriptler script for giving mychoice parameter the available options.
return list
欲瞭解更多信息,請參閱參考文章這裏:https://stackoverflow.com/questions/45336944/how-to-get-ordered-defined-or-all-columns-except-or-after-or-before-a-given -COL –
謝謝你伊戈爾。我已添加您提供的代碼。但是,當我選擇參數構建,理想情況下,我應該看到abc,def,ghi等,但我什麼也沒看到...... –
@RohitSavanurkar你檢查了你的腳本嗎?你可以在http://中運行它,看看它是否從文件中返回這些值。 –
不,我仍然沒有看到任何東西,當我運行jenkins工作... –