Jenkins parameterized build changing default value

对着背影说爱祢 提交于 2019-12-13 01:50:01

问题


I am using the Jenkins "extended choice parameter" plugin and want to schedule the build to run periodically without human intervention.

The parameter for the build is selected from a drop down list.

The drop down list for the parameter is generated through an external script and I always want to pick the top most value as the default value.

Is there a way to select the top most element as the default value for the scheduled job?

I read there are ways to run a job remotely using the url but I am hoping that I can achieve this by making changes just to the job configuration so that I don't have to manage a separate script for it.

My Jenkins instance is running on Linux and I would like to only run this job using the Build Trigger --> Build Periodically section of a Jenkins job configuration.


回答1:


Well, if you really want only the latest to be picked up as default by your scheduled job, you will have to modify the external script that you use to populate the drop-down menu. I'm not sure how you're populating the list through an external script but i know a way which i have used and works perfectly fine for me. I also use an external script to generate a list and i store that list in a file. In your case, things will be a little different. We will discuss that further.

First, select the following options in Extended Choice Parameter:

  1. In Simple Parameter Types section, go for Single Select in Parameter Type

  2. Instead of Choose Source for Value, go for Choose Source for Default Value. Here, select Default Property File and specify the path of the file which will be generated by the external script.

Since you have to select only the latest from the list, this effectively means that providing only the latest entry in the stored file should suffice. When your external script runs and generates the list, simply store the latest in the file. This file will then be picked up by Jenkins and you’re good to go.

For specifying Default Property Key, refer this link. In the given link, I have also provided the command with which you can generate the file in a format which will be correctly interpreted by Jenkins while loading the file. That will give you an idea for your case. Only difference in your case will be that you will have to filter out only the latest and then store that single entry in the file.

P.S.: Make sure that the property file is on Jenkins Master (in case of Master-Slave setup).



来源:https://stackoverflow.com/questions/25766576/jenkins-parameterized-build-changing-default-value

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!