扩展Jenkins Groovy DSL [英] Extending the Jenkins Groovy DSL

查看:377
本文介绍了扩展Jenkins Groovy DSL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在我的Jenkins实例中添加/编辑新代码,以便在DSL脚本中访问?内容如下

我继承了一个Jenkins实例。这种继承的一部分包括在闹鬼的房子里度过夜晚写一些新的自动化在groovy 通过乔布斯DSL插件 。由于我害怕破坏我们的jenkins实例,我的第一步是建立一个本地开发实例。



我在本地开发实例上运行我们现有的一个 DSL脚本时遇到问题 - 我在本地服务器上的构建失败,在Jenkins错误控制台中。

 处理DSL脚本jobs.groovy 
错误:启动失败:
jobs.groovy:1:无法解决类thecompanysname.jenkins.extensions

有问题的脚本开始/ b>

  import thecompanysname.jenkins.extensions 

use(extensions){
def org ='project-name'
def project ='test-jenkins-repo'
def _email ='foo@example.com'

所以,据我所知,看起来像一个predecesor已经编写了一些自定义的Groovy代码,它们正在导入

  import thecompanysname.jenkins.extensions 

什么不是明白我是


  1. 这里代码生命

  2. 我可以在真正的Jenkins实例中找到它

  3. 我可以如何添加到我的本地实例中

欢迎提供具体答案,因为我们的是您如何学习钓鱼答案。

解决方案

虽然可能有其他方法可以完成此操作, b


  1. 我安装的Jenkins实例具有旧版本的作业DSL插件

  2. 这个版本的Jobs DSL插件允许您在 中设置额外的 classpath 处理DSL构建作业部分,该部分指向其他 jar 文件。这些jar文件可以让你访问groovy脚本中的其他类(即 thecompanysname.jenkins.extensions DSL插件已经将这个删除了选项,目前尚不清楚是否可以添加它。然而,这是另一个问题。

    How can I add/edit new code to my Jenkins instance that would be accesible in a DSL script? Context follows

    I've inherited a Jenkins instance. Part of this inheritance includes spending the night in a haunted house writing some new automation in groovy via the Jobs DSL plugin. Since I'm fearful of ruining our jenkins instance, my first step is setting up a local development instance.

    I'm having trouble running one of our existing DSL Scripts on my local development instance -- my builds on the local server fail with the following in the Jenkins error console.

    Processing DSL script jobs.groovy
    ERROR: startup failed:
    jobs.groovy: 1: unable to resolve class thecompanysname.jenkins.extensions
    

    The script in question starts off like this.

    import thecompanysname.jenkins.extensions
    
    use(extensions) {
      def org = 'project-name'
      def project = 'test-jenkins-repo'
      def _email = 'foo@example.com'
    

    So, as near I can tell, it seems like a predecesor has written some custom Groovy code that they're importing

    import thecompanysname.jenkins.extensions
    

    What's not clear to me is

    1. Where this code lives
    2. How I can find it in our real Jenkins instance
    3. How I can add to to my local instance

    Specific answers are welcome, as our here's how you can learn to fish answers.

    解决方案

    While there may be other ways to accomplish this, after a bit of poking around I discovered

    1. The Jenkins instance I've installed has an older version of the Jobs DSL plugin installed.

    2. This version of the Jobs DSL plugin allowed you to set an additional classpath in your Process DSL Builds job section that pointed to additional jar files.

    3. These jar files can give you access to additional classes in your groovy scripts (i.e. thecompanysname.jenkins.extensions)

    Unfortunately, more recent versions of the Jobs DSL plugin have removed this option, and it's not clear if it's possible to add it back. That, however, is another question.

    这篇关于扩展Jenkins Groovy DSL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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