1

I am trying to deploy the jenkins pod through docker and configure the Jenkins Jobs through the scripts. Using some of below restAPIs

a) https://<hostname>/scriptText
b) https://<hostname>/job//build
c) https://<hostname>/job/api/json
.
.
and more

However when I start building jobs, its getting failed due to the error ERROR: Unable to install JDK unless a valid username/password is provided.

It needs to change the configurations from Manage Jenkins -> Global Tool Configuration -> JDK -> JDK Installations

But there is no any restAPI available to perform this task.

Is there any way to change the jenkins global configuration programatically?

va1bhav
  • 365
  • 1
  • 5
  • 21
  • I am not sure i understood the problem: if your goal is to install JDK on runtime if needed automatic you can go to the URL: :8080/configureTools/ Press JDK, Give name-> Install automatic -> Install from Java sun (press i agree button) – Oron Golan Aug 09 '18 at 07:14
  • @OronGolan proper JDK version already installed on master/slave nodes. But I want to change the default configuration of jenkins "Global Tool Configuration" about JDK which asks to install JDK on each build start using script (Not using UI). – va1bhav Aug 09 '18 at 07:36

1 Answers1

1

One solution I found is that, set username and password to download the JDK from oracle site in Global Tool Configuration.

To do it, execute below groovy script using scriptText rest api

set_username_password.groovy

import jenkins.model.*
import hudson.model.*

def inst = Jenkins.getInstance()
def desc = inst.getDescriptor("hudson.tools.JDKInstaller")
#create user account here: http://www.oracle.com/technetwork/java/javase/downloads/index.html
println desc.doPostCredential('<username>','<password>')

Execute the rest api as

curl --user <jk_username>:<jk_password> --data-urlencode "script=$(cat set_username_password.groovy)" -X POST "https://<hostname>/scriptText"

References:

https://github.com/glenjamin/jenkins-groovy-examples/blob/master/README.md

http://javadoc.jenkins.io/archive/jenkins-2.73/hudson/tools/JDKInstaller.DescriptorImpl.html

va1bhav
  • 365
  • 1
  • 5
  • 21