Using JavaScript within jelly script
javascript, jelly, jenkins
Solution
For the question "where should I put my JS file" you can put in src/main/webapp and in jelly file you can write `<script src="${rootURL}/plugin/plugin_name/myCustom.js"/>`
Problem
I'm trying to use scripts written in JavaScript in Jenkins. I think that the easiet way would be to call them in .jelly scripts. For example: I have file myCustom.js: ``` alert("Hello World!"); function myFunction() { var x = "", i; for (i=0; i<5; i++) { x = x + "The number is " + i + "<br>"; } document.getElementById("demo").innerHTML = x; } ``` Next I have: global.jelly (from tutorial plugin): ``` <j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define" xmlns:l="/lib/layout" xmlns:t="/lib/hudson" xmlns:f="/lib/form"> <f:section title="Hello World Builder"> <f:entry title="French" field="useFrench" description="Check if we should say hello in French"> <f:checkbox /> <script type="text/javascript" src="${resURL}/myCustom.js"> </script> </f:entry> </f:section> </j:jelly> ``` The problem is that: there is no effect! Even the Hello World allert does not show... What am I doing wrong? If I use: ``` <script type="text/javascript" > alert("Hello World!"); </script> ``` in jelly, it shows allert window, but I cannot call entire document. Maybe "${resURL}/myCustom.js" is not pointing correctly? where should I put my JS file? One more thing: I've seen other question on Stack, but there is no working anwser, and I can't contact to owner of that one.