add build parameter in jenkins build schedule

ぃ、小莉子 提交于 2019-12-18 02:19:04

问题


I have a jenkins job. i want to build my job in a specific time with a build parameter.

I want to do this by using the Build periodically option.

I have input like this:

*/1 * * * * Parameter1

If I do this, jenkins show an error.

Is this possible without using any plugin.

if not, than which plugin will be better

Alternatively is there a way to give parameter's here in the schedule?

My actual requirement is like this:

 build in morning using one parameter
 build in evening using another parameter.    

回答1:


Basically, with the Build periodically option you can't schedule a Jenkins job with parameters.

However, to schedule a job at different times that needs to use different environments, you've to use the parameterized-scheduler plugin as mentioned above https://github.com/jwmach1/parameterized-scheduler or search it in (Manage Jenkins -> Manage Plugins -> Parameterized Scheduler). so it'll be like #Parameter1 H/15 * * * * %Parameter1 #Parameter2 H/30 * * * * %Parameter2 Remember you have to have your parameters already setup because the plugin is visible only for jobs with parameters.

The Node and Label parameter plugin can help since it allows you to select individual nodes assuming your different servers qa1 and qa2 are already configured. Hope that clarifies things for you.




回答2:


With the native Jenkins crontab, it's not possible.

But it should be possible with this plugin: https://github.com/jwmach1/parameterized-scheduler

You have to fork the repo and build this plugin + do a manual installation.

This tutorial explains how to build a custom plugin: https://wiki.jenkins-ci.org/display/JENKINS/Plugin+tutorial

(Setting Up Environment + Building a Plugin)




回答3:


Maybe not exactly what you want, but it is an interesting hack I found out so I decided to share. You can programmatically set parameters of Jenkins job depending on the environment.

# check if job was trigered by timer
if [ $(env | grep -E '^BUILD_CAUSE=TIMERTRIGGER$') ] ; then 
  # your logic here, utilise the power of bash   
  if [ $(date +"%H") -eq 16 ] ; then PARAM=VALUE_1 ; fi
  if [ $(date +"%H") -eq 17 ] ; then PARAM=VALUE_2 ; fi
fi



回答4:


Without plugins, you can try cloning the job, and creating a build schedule with different parameter values. I.e. you might have job_morning and job_evening.

See How do I clone a job in jenkins?



来源:https://stackoverflow.com/questions/34594703/add-build-parameter-in-jenkins-build-schedule

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