Hi ,
Currenly i am working on a Jenkins plugin where i need to disable job with OnClick event of a button. For this I am calling a java function (
doDisable) from Java script onclick event. When I am trying, I am getting below error.
Jan 24, 2018 6:48:04 PM hudson.security.csrf.CrumbFilter doFilter
WARNING: No valid crumb was included in request for /jenkins/$stapler/bound/37592385-13a3-46a8-a03d-07bb25b6564e/doDisable. Returning 403. On Disable CSRF, i am able to call my java function from java script.
I want to know how to pass crumbs to jenkins in this case. Also is there any other approach to do disable job with button onClick event.
Function defined in my java class
@JavaScriptMethod
public void doDisable(){
Item job = Jenkins.getInstance().getItemByFullName("JobName");
if(job instanceof hudson.model.FreeStyleProject){
try {
((FreeStyleProject) job).disable();
} catch(IOException ie) {
ie.printStackTrace();
}
}
}
main.jelly
<button onclick="MakeJobDisable()">Click me</button>
<script>
var foo = <st:bind value="${section}"/>
function MakeJobDisable() {
foo.doDisable(function(t) {
})
}
</script>
Reference URL : https://wiki.jenkins.io/display/JENKINS/AJAX+with+JavaScript+proxy