Using JavaScript within jelly script

雨燕双飞 提交于 2019-12-07 11:57:10

问题


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.


回答1:


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"/>




回答2:


Put your script inside the tag and create a folder js inside web-app folder.



来源:https://stackoverflow.com/questions/24734159/using-javascript-within-jelly-script

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!