How to make a Jenkins/Hudson job surveil some others jobs and decide whether to build or not?

。_饼干妹妹 提交于 2019-11-27 11:51:23

Here are some hints and code snippets:

  • There is a Groovy Script console at http://<jenkins-server>/script that will help you with debugging your scripts.
  • Here is a link to Jenkins Java API.
  • Code snippet that outputs all job names:

    def hi = hudson.model.Hudson.instance
       hi.getItems(hudson.model.Project).each {project ->
       println(project.displayName)
    }
    
  • Code snippet that extracts n from LEVEL_n (implemented as closure):

    def level = { name ->
      def ret = 0
      name.eachMatch(~'LEVEL_([1-9]+[0-9*])', {ret = it[1].toInteger()})
      return ret
    }
    
  • Code snippet that gets statuses for all the latest builds:

    def hi = hudson.model.Hudson.instance
    hi.getItems(hudson.model.Project).each {project ->
      println(project.lastBuild.result)
    }
    
  • Link to the method that starts a build.

Note: things get a bit hairier if you are using Matrix builds. But as long as you don't this should be enough.

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