0

I don't need cron job because the build is needed to run only once in production and not periodically.Is there a way to build the pipeline at a scheduled time without cron.

2 Answers2

1

You can schedule a build using Groovy via script console or job using: scheduleBuild2:

def waittime = 100   // in secs
def jobName = 'folder/jobname'   //aka it.fullName

Jenkins.instance.getItemByFullName(jobName).scheduleBuild2(waittime)

quietPeriod - seconds to wait before starting (normally 0)

public QueueTaskFuture<R> scheduleBuild2(int quietPeriod, Action... actions)

Description copied from interface: ParameterizedJobMixIn.ParameterizedJob Provides a standard implementation of SCMTriggerItem.scheduleBuild2(int, hudson.model.Action...) to schedule a build with the ability to wait for its result. That job method is often used during functional tests (JenkinsRule.assertBuildStatusSuccess).

Specified by: scheduleBuild2 in interface ParameterizedJobMixIn.ParameterizedJob<P extends AbstractProject<P,R>,R extends AbstractBuild<P,R>> Parameters: quietPeriod - seconds to wait before starting (normally 0) actions - various actions to associate with the scheduling, such as ParametersAction or CauseAction Returns: a handle by which you may wait for the build to complete (or just start); or null if the build was not actually scheduled for some reason

Ian W
  • 4,559
  • 2
  • 18
  • 37
0

One way to do is - You can trigger it remotely https://www.jenkins.io/doc/book/using/remote-access-api/

Let's say you got a Linux box, you can schedule it by using the "at" command

at 9:30 PM Fri

curl -X POST JENKINS_URL/job/JOB_NAME/build \
  --data token=TOKEN \
  --data-urlencode json='{"parameter": [{"name":"id", "value":"123"},\
     {"name":"verbosity", "value":"high"}]}'
job 2 at Fri Jan 29 21:30:00 2016

Then look at it with

at -c 2
Pankaj Saini
  • 1,493
  • 8
  • 13