使用松弛通知更新现有jenkins作业的groovy脚本

时间:2017-04-20 07:03:33

标签: jenkins groovy

我正在尝试使用松弛通知插件更新现有的jenkins作业。

长期坚持这一点,有人可以指导我吗?感谢你的帮助。

在jenkins脚本控制台中尝试了以下内容:

for (item in Jenkins.instance.getItemByFullName("TestJob")) {
  item.publishersList.replace(new jenkins.plugins.slack.SlackNotifier('http://example.com', 'chann', 'jkkljh7777kkjlkj', false, '', '', '', true, true, true, true, true, true, true, true, true, true, true, null, true, 'hmm'))
}

收到以下错误。

  

groovy.lang.GroovyRuntimeException:找不到匹配的构造函数:jenkins.plugins.slack.SlackNotifier(java.lang.String,java.lang.String,java.lang.String,java.lang.Boolean,java。 lang.String,java.lang.String,java.lang.String,java.lang.Boolean,java.lang.Boolean,java.lang.Boolean,java.lang.Boolean,java.lang.Boolean,java.lang。 Boolean,java.lang.Boolean,java.lang.Boolean,java.lang.Boolean,java.lang.Boolean,java.lang.Boolean,null,java.lang.Boolean,java.lang.String)       at groovy.lang.MetaClassImpl.invokeConstructor(MetaClassImpl.java:1731)       at groovy.lang.MetaClassImpl.invokeConstructor(MetaClassImpl.java:1534)       在org.codehaus.groovy.runtime.callsite.MetaClassConstructorSite.callConstructor(MetaClassConstructorSite.java:49)       在org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallConstructor(CallSiteArray.java:60)       在org.codehaus.groovy.runtime.callsite.AbstractCallSite.callConstructor(AbstractCallSite.java:235)       在Script1.run(Script1.groovy:2)       在groovy.lang.GroovyShell.evaluate(GroovyShell.java:585)       在groovy.lang.GroovyShell.evaluate(GroovyShell.java:623)       在groovy.lang.GroovyShell.evaluate(GroovyShell.java:594)       在hudson.util.RemotingDiagnostics $ Script.call(RemotingDiagnostics.java:142)       在hudson.util.RemotingDiagnostics $ Script.call(RemotingDiagnostics.java:114)       在hudson.remoting.LocalChannel.call(LocalChannel.java:45)       在hudson.util.RemotingDiagnostics.executeGroovy(RemotingDiagnostics.java:111)       在jenkins.model.Jenkins._doScript(Jenkins.java:4295)       在jenkins.model.Jenkins.doScript(Jenkins.java:4267)       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)       在org.kohsuke.stapler.Function $ InstanceFunction.invoke(Function.java:335)       在org.kohsuke.stapler.Function.bindAndInvoke(Function.java:175)       在org.kohsuke.stapler.Function.bindAndInvokeAndServeResponse(Function.java:108)       在org.kohsuke.stapler.MetaClass $ 1.doDispatch(MetaClass.java:124)       在org.kohsuke.stapler.NameBasedDispatcher.dispatch(NameBasedDispatcher.java:58)       在org.kohsuke.stapler.Stapler.tryInvoke(Stapler.java:746)       在org.kohsuke.stapler.Stapler.invoke(Stapler.java:876)       在org.kohsuke.stapler.Stapler.invoke(Stapler.java:649)       在org.kohsuke.stapler.Stapler.service(Stapler.java:238)       在javax.servlet.http.HttpServlet.service(HttpServlet.java:723)       在org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)       在org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)       在hudson.util.PluginServletFilter $ 1.doFilter(PluginServletFilter.java:135)       在org.jenkinsci.plugins.corsfilter.AccessControlsFilter.doFilter(AccessControlsFilter.java:79)       在hudson.util.PluginServletFilter $ 1.doFilter(PluginServletFilter.java:132)       at com.smartcodeltd.jenkinsci.plugin.assetbundler.filters.LessCSS.doFilter(LessCSS.java:47)       在hudson.util.PluginServletFilter $ 1.doFilter(PluginServletFilter.java:132)       在hudson.plugins.greenballs.GreenBallFilter.doFilter(GreenBallFilter.java:59)       在hudson.util.PluginServletFilter $ 1.doFilter(PluginServletFilter.java:132)       在hudson.plugins.audit_trail.AuditTrailFilter.doFilter(AuditTrailFilter.java:95)       在hudson.util.PluginServletFilter $ 1.doFilter(PluginServletFilter.java:132)       在hudson.util.PluginServletFilter.doFilter(PluginServletFilter.java:126)       在org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)       在org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)       在hudson.security.csrf.CrumbFilter.doFilter(CrumbFilter.java:80)       在org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)       在org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)       在hudson.security.ChainedServletFilter $ 1.doFilter(ChainedServletFilter.java:84)       at hudson.security.UnwrapSecurityExceptionFilter.doFilter(UnwrapSecurityExceptionFilter.java:51)       在hudson.security.ChainedServletFilter $ 1.doFilter(ChainedServletFilter.java:87)       在jenkins.security.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:117)       在hudson.security.ChainedServletFilter $ 1.doFilter(ChainedServletFilter.java:87)       在org.acegisecurity.providers.anonymous.AnonymousProcessingFilter.doFilter(AnonymousProcessingFilter.java:125)       在hudson.security.ChainedServletFilter $ 1.doFilter(ChainedServletFilter.java:87)       在org.acegisecurity.ui.rememberme.RememberMeProcessingFilter.doFilter(RememberMeProcessingFilter.java:142)       在hudson.security.ChainedServletFilter $ 1.doFilter(ChainedServletFilter.java:87)       at org.acegisecurity.ui.AbstractProcessingFilter.doFilter(AbstractProcessingFilter.java:271)       在hudson.security.ChainedServletFilter $ 1.doFilter(ChainedServletFilter.java:87)       在jenkins.security.BasicHeaderProcessor.doFilter(BasicHeaderProcessor.java:93)       在hudson.security.ChainedServletFilter $ 1.doFilter(ChainedServletFilter.java:87)       at org.acegisecurity.context.HttpSessionContextIntegrationFilter.doFilter(HttpSessionContextIntegrationFilter.java:249)       在hudson.security.HttpSessionContextIntegrationFilter2.doFilter(HttpSessionContextIntegrationFilter2.java:67)       在hudson.security.ChainedServletFilter $ 1.doFilter(ChainedServletFilter.java:87)       在hudson.security.ChainedServletFilter.doFilter(ChainedServletFilter.java:76)       在hudson.security.HudsonFilter.doFilter(HudsonFilter.java:171)       在org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)       在org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)       at org.kohsuke.stapler.compression.CompressionFilter.doFilter(CompressionFilter.java:49)       在org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)       在org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)       在hudson.util.CharacterEncodingFilter.doFilter(CharacterEncodingFilter.java:82)       在org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)       在org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)       在org.kohsuke.stapler.DiagnosticThreadNameFilter.doFilter(DiagnosticThreadNameFilter.java:30)       在org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)       在org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)       在org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)       at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)       在org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:558)       在org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)       at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)       在org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)       在org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:299)       在org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:857)       在org.apache.coyote.http11.Http11Protocol $ Http11ConnectionHandler.process(Http11Protocol.java:588)       在org.apache.tomcat.util.net.JIoEndpoint $ Worker.run(JIoEndpoint.java:489)       在java.lang.Thread.run(Thread.java:745)

1 个答案:

答案 0 :(得分:0)

我使用Slack Notification Plugin并像这样发布到Slack:

stage('notify') { withCredentials([[$class: 'StringBinding', credentialsId: 'my-id', variable: 'my-slack-token']]) { slackSend(message: "my status message", teamDomain: 'my-team', token: env.my-slack-token, channel: '#my-channel', color: 'good') } }

请记住,您需要为Slack集成令牌创建凭据(我称之为my-credentials-id,然后将该值赋予变量my-slack-token)。您可以在"管理Jenkins"中创建该凭证。 > "证书"

抱歉格式化。 :(