Can I schedule a Jenkins Build without CRON or REST API?

952 views Asked by At

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...

1

There are 1 answers

0
R. Karlus On

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.