
Question:
I am using the Jenkins <strong>"extended choice parameter"</strong> 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.
Answer1:Well, if you really want only the latest to be picked up as default by your <em>scheduled</em> 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. <em>In your case, things will be a little different</em>. We will discuss that further.
First, select the following options in Extended Choice Parameter
:<br />
In Simple Parameter Types
section, go for Single Select
in Parameter Type
<br />
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.
<img alt="enter image description here" class="b-lazy" data-src="https://i.stack.imgur.com/5ypxE.png" data-original="https://i.stack.imgur.com/5ypxE.png" src="https://etrip.eimg.top/images/2019/05/07/timg.gif" />
Since you have to select only the latest from the list, this effectively means that <em>providing only the latest entry in the stored file should suffice</em>. 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 <a href="https://stackoverflow.com/questions/25640028/select-branch-to-build-in-jenkins/25642499#25642499" rel="nofollow">this</a> 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 <em>single</em> entry in the file.
<strong>P.S.</strong>: Make sure that the property file is on Jenkins Master (in case of Master-Slave setup).