0

To schedule a build in Jenkins I need to add a "cron" parameter then all works well. But I have a lot of donkey users and they didn't know how to schedule with cron.

Is there a way to schedule a Jenkins build without the API itself (http://jenkins/job/jobname/build?delay=4000 I don't want this) or cron? Maybe some Jenkins Plugin...

R. Karlus
  • 2,094
  • 3
  • 24
  • 48
  • Too many answers, see [Build trigger plugins](https://wiki.jenkins-ci.org/display/JENKINS/Plugins#Plugins-Buildtriggers). Why bother with scheduling when you can trigger on SCM commits? – Dave Bacher Jun 11 '15 at 15:55
  • Thanks Dave but, as I say, I have some noob users and they don't develop. I've developed a web page to call my Jenkins API through a cURL with token authentication. Now I can schedule any job. – R. Karlus Jun 12 '15 at 19:31

1 Answers1

0

Solved it this way:

<?php
if($_POST) {
    $fields = array(
        "POST_PARAMETERS" => $_POST['params']
    );
    $delay = (int) $_POST['delay'];
    $username = "my_username";
    $password = "my_password";
    $token = "MY_JENKINS_TOKEN_NAME";
    $job = "JOB_NAME";
    $url = "http://jenkins_host/jenkins/job/".$job."/buildWithParameters?token=".$token."&delay=".$delay;

    $process = curl_init($url);
    curl_setopt($process, CURLOPT_HEADER, 1);
    curl_setopt($process, CURLOPT_USERPWD, $username . ":" . $password);
    curl_setopt($process, CURLOPT_TIMEOUT, 30);
    curl_setopt($process, CURLOPT_POST, 1);
    curl_setopt($process, CURLOPT_RETURNTRANSFER, TRUE);
    curl_setopt($process, CURLOPT_POSTFIELDS, http_build_query($fields));
    curl_setopt($process, CURLOPT_POST, count($fields));
    $return = curl_exec($process);
    echo http_build_query($fields);
    echo curl_error($process);
    curl_close($process);
    die;
}
?>

I give the JOB_NAME and the build parameters and it work well. cURL did the trick for me with the authorization token.

Thanks everyone who tried to help.

R. Karlus
  • 2,094
  • 3
  • 24
  • 48