Reputation: 21
I am new to Jenkins. I am trying some basic functions using radio buttons.
In the below code it seems to have a problem displaying prevJob value. When i select either radio buttons, no value is returned (value should be display to the right of HANDLE_VERSION (Image provided)). However the code works in Jenkin's Script Console. I tried some other functions such as def
jobName = this.binding.jenkinsProject.name
And that worked and return the current job name when selecting the radio button.
Why is that? Eventually i would like to get the prev build version and handle some logic which will adjust the build version for the user before kicking off the job. Any clarity/help would be greatly appreciative. Thank you!
switch(MAJOR_OR_MINOR){
case~/.*Major.*/:
//vOption="Major"
def jobName = "Test"
def job = Jenkins.instance.getItem(jobName)
def prevJob = (job.getBuilds()[0]).toString()
return "<b>${prevJob}</b>"
break
case~/.*Minor.*/:
//vOption="Minor"
def jobName = "Test"
def job = Jenkins.instance.getItem(jobName)
def prevJob = (job.getBuilds()[0]).toString()
return "<b>${prevJob}</b>"
break
}
Here are some screenshots:
Upvotes: 1
Views: 1106
Reputation: 21
Solved: Sorry, i realized that i did not import my packages. import hudson.model.*; import jenkins.model.Jenkins
Upvotes: 1