2017-06-06 11 views
0

私はJenkinsにインストールされているアクティブな選択肢のパラメータを持っています。ここでは、ローカルに保存されたテキストファイルから値を選択して、これを複数選択オプションとしてユーザーに表示する必要があります。 たとえば、私のテキストファイルは1 - abc、2 - defというエントリを持つことができます。ユーザは両方のエントリを見なければならず、それらのエントリのいずれかまたは両方を選択することができる。このテキストファイルは手動で管理されます。私は3番目のエントリを持つことができます - ghiと私はジェンキンスの仕事をトリガするとき、私はすべての3つのエントリを表示する必要があります。アクティブな選択パラメータ

誰でもお手伝いできますか?

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 

また、複数の値については、「選択肢タイプ」を選択します。

はあなたが好きなものは、ファイルを解析し、オプションを返すようにグルーヴィーなスクリプトを使用することができ、事前に のRohit

答えて

0

、ありがとうございました。

+0

はあなたのイゴールに感謝します。私はあなたから提供されたコードを追加しました。しかし、パラメータを使ってBuildを選択すると、abc、def、ghiなどが表示されるはずですが、何も表示されません。 –

+0

@RohitSavanurkarスクリプトを確認しましたか? http:// で実行し、ファイルからそれらの値が返されるかどうかを確認できます。 –

+0

いいえ、私はジェンキンスジョブを実行している間は何も表示されません... –

0

これを試してみてください:

// 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 
+0

詳しくは、参照先の記事を参照してください。https://stackoverflow.com/questions/45336944/how-to-get-ordered-defined- or-all-columns-except-or-after-or-after-before-a-given -col –

関連する問題