Aspirant9
Aspirant9

Reputation: 165

How to run job on jenkins that need authentication using Rest API?

I want to create a Javascript Application that talks to a jenkins server hosted (say http://myjenkinsserver.com/jenkins. This jenkins server needs a user to be authenticated to run any job. The authentication needed is BASIC Http. I have my username: johnsmith and password: jenkinsjob. I also have the API token.

My doubt is how do i authenticate and store any token somewhere to use it to start/stop builds etc.

Thanks in advance.

P.S: Reference -

https://wiki.jenkins-ci.org/display/JENKINS/Remote+access+API

https://wiki.jenkins-ci.org/display/JENKINS/Authenticating+scripted+clients

Upvotes: 0

Views: 1313

Answers (2)

Endorox
Endorox

Reputation: 99

Had a smiliar problem. Try looking at This HTTP Pluggin.

function LastSuccessfulBuild(callback, iParams) {
    $http({
        method: 'POST',
        url: (iParams.url+"/job/"+iParams.job+"/lastSuccessfulBuild"),
        username: myUsername,
        password: myPassword,
    }).then(function successCallback(response) {
        getSuccess(callback, response)
    }, function errorCallback(response) {
        getFailed(response);
    });
}

Works for me

Upvotes: 0

Nicolas Albert
Nicolas Albert

Reputation: 2596

You can use jQuery and its jQuery.ajax function that defined a username and password options.

Then, you can store your token in a localStorage.

Upvotes: 1

Related Questions