在果冻脚本中使用JavaScript [英] Using JavaScript within jelly script

查看:174
本文介绍了在果冻脚本中使用JavaScript的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用Jenkins中用JavaScript编写的脚本. 我认为最简单的方法是在.jelly脚本中调用它们. 例如:我有文件

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;
}

接下来我有: global.jelly (来自教程插件):

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

问题在于:没有效果!甚至Hello World allert也不会显示... 我究竟做错了什么? 如果我使用:

<script type="text/javascript" >
    alert("Hello World!");
</script>

在果冻中,它显示了allert窗口,但我无法调用整个文档. 也许"$ {resURL}/myCustom.js" 指向不正确?我应该在哪里放置我的JS文件?

另一件事:我在Stack上看到了另一个问题,但是没有可用的答案,并且我无法与该问题的所有者联系.

解决方案

对于我应该在哪里放置我的JS文件"的问题,您可以将其放置在src/main/webapp中,而在果冻文件中则可以编写<script src="${rootURL}/plugin/plugin_name/myCustom.js"/>

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.

解决方案

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

这篇关于在果冻脚本中使用JavaScript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆