node.js - Groovy Script for Nodejs 插件无法在 Jenkins 上配置

标签 node.js jenkins groovy jenkins-plugins chef-recipe

我觉得我缺少 Nodejs 插件的数据绑定(bind)构造函数,其中写着“List extends hudson.tools.ToolProperty properties”

import jenkins.model.*
import hudson.tools.*
import jenkins.plugins.nodejs.tools.*

def inst = Jenkins.getInstance()

def desc = inst.getDescriptor(jenkins.plugins.nodejs.NodeJSInstaller)

def sinst = new NodeJSInstallation("nodejs12", "/usr/local/bin/node/")

desc.setInstallations(sinst)

desc.save()

Error:

    Mixlib::ShellOut::ShellCommandFailed
    ------------------------------------
    Expected process to exit with [0], but received '1'
    ---- Begin output of "java" -jar "/var/chef/cache/jenkins-cli.jar" -s http:/
    /localhost:8080 groovy /tmp/groovy20160225-23006-1a7g9ix ----
    STDOUT:
    STDERR: ERROR: Unexpected exception occurred while performing groovy command
.
    groovy.lang.MissingPropertyException: No such property: Jenkins for class: RemoteClass 
    at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap(ScriptBytecodeAdapter.java:50)
        at org.codehaus.groovy.runtime.callsite.PogoGetPropertySite.getProperty(PogoGetPropertySite.java:49)
        at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callGroovyObjectGetProperty(AbstractCallSite.java:231)
        at RemoteClass.run(RemoteClass:6)
        at groovy.lang.GroovyShell.runScriptOrMainOrTestOrRunnable(GroovyShell.java:266)
        at groovy.lang.GroovyShell.run(GroovyShell.java:517)
        at hudson.cli.GroovyCommand.run(GroovyCommand.java:86)
        at hudson.cli.CLICommand.main(CLICommand.java:256)
        at hudson.cli.CliManagerImpl.main(CliManagerImpl.java:92)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:606)
        at hudson.remoting.RemoteInvocationHandler$RPCRequest.perform(RemoteInvocationHandler.java:608)
        at hudson.remoting.RemoteInvocationHandler$RPCRequest.call(RemoteInvocationHandler.java:583)
        at hudson.remoting.RemoteInvocationHandler$RPCRequest.call(RemoteInvocationHandler.java:542)
        at hudson.remoting.UserRequest.perform(UserRequest.java:120)
        at hudson.remoting.UserRequest.perform(UserRequest.java:48)
        at hudson.remoting.Request$2.run(Request.java:326)
        at hudson.remoting.InterceptingExecutorService$1.call(InterceptingExecutorService.java:68)
        at hudson.cli.CliManagerImpl$1.call(CliManagerImpl.java:63)
        at hudson.remoting.CallableDecoratorAdapter.call(CallableDecoratorAdapter.java:18)
        at hudson.remoting.CallableDecoratorList$1.call(CallableDecoratorList.java:21)
        at jenkins.util.ContextResettingExecutorService$2.call(ContextResettingExecutorService.java:46)
        at java.util.concurrent.FutureTask.run(FutureTask.java:262)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
        at java.lang.Thread.run(Thread.java:745)
    ---- End output of "java" -jar "/var/chef/cache/jenkins-cli.jar" -s http://localhost:8080 groovy /tmp/groovy20160225-23006-1a7g9ix ----
    Ran "java" -jar "/var/chef/cache/jenkins-cli.jar" -s http://localhost:8080 groovy /tmp/groovy20160225-23006-1a7g9ix returned 1

    Cookbook Trace:
    ---------------
    /var/chef/cache/cookbooks/jenkins/libraries/_executor.rb:84:in `execute!'
    /var/chef/cache/cookbooks/jenkins/libraries/_executor.rb:137:in `groovy!'
    /var/chef/cache/cookbooks/jenkins/libraries/script.rb:48:in `block (2 levels) in <class:JenkinsScript>'
    /var/chef/cache/cookbooks/jenkins/libraries/script.rb:47:in `block in <class:JenkinsScript>'

    Resource Declaration:
    ---------------------
    # In /var/chef/cache/cookbooks/jenkins/recipes/nodeconfig.rb

      3: jenkins_script 'nodejs' do
      4:   command <<-EOH.gsub(/^ {4}/, '')
      5:
      6: import hudson.model.*
      7: import hudson.tools.*
      8: import jenkins.plugins.nodejs.tools.*
      9:
     10: def inst = Jenkins.getInstance()
     11:
     12: def desc = inst.getDescriptor(jenkins.plugins.nodejs.NodeJSInstaller)
     13:
     14: def sinst = new NodeJSInstallation("nodejs12", "/usr/local/bin/node")
     15:
     16: desc.setInstallations(sinst)
     17:
     18: desc.save()
     19:
     20: EOH
     21: end

我无法理解这个错误,因为我对 Java 知之甚少,而且我是 Jenkins 的新手。

最佳答案

jenkins 上的 Nodejs 插件的 Groovy 脚本

import hudson.model.*
import hudson.tools.*
import jenkins.plugins.nodejs.tools.*
import jenkins.model.*

def inst = Jenkins.getInstance()
def desc = inst.getDescriptor(jenkins.plugins.nodejs.tools.NodeJSInstallation)
def installer = new NodeJSInstaller("NodeJS version", "some npm package", npm package refresh hours(integer))

def prop = new InstallSourceProperty([installer])
def sinst = new NodeJSInstallation("Name of installation(string-tag)", "/path/to/nodejs/executable",[prop])

desc.setInstallations(sinst)
desc.save()

关于node.js - Groovy Script for Nodejs 插件无法在 Jenkins 上配置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35627360/

相关文章:

groovy - 停止 Gradle 构建的推荐方法

node.js - 使用 Node.js 通过自定义 API 向设备(ios 或 android)发送通知

node.js - 测试 AWS S3 Presigned Url 返回 403 Forbidden (Nodejs)

javascript - 如果没有被拒绝, promise 链式结果

git - 尝试从 Bitbucket checkout 时,Jenkins 删除了工作区

groovy - 如何在 Groovy 范围对象中做到这一点?

Node.JS:使用 Sequelize 时无法连接到 Microsoft Azure 数据库

email - 如何使用 Jenkins 和参数地址发送电子邮件?

git - 没有这样的文件 : ‘pom.xml’ error in jenkins

Gradle Ear 插件 : Adding modules without version specifier