如何以编程方式在Hudson的视图中构建作业。

huangapple go评论117阅读模式
英文:

How to programmatically build a jobs in a view in hudson

问题

我在特定视图中有 500 多个 Jenkins 任务。我需要使用 Jenkins 脚本控制台以编程方式触发这些任务。我尝试了下面的代码,但没有成功。
英文:

I have a 500+ Jenkins jobs in a particular view. I need to trigger those jobs programmatically using the Jenkins script console. I tried with the below code but it didn't work.

    import hudson.model.*;
    triggerbuild{
      def job = hudson.instance.getview("xxxx").listItem("Job")
      hudson.instance.build("job")
}

Can someone help me on this?

答案1

得分: 0

这是我能想出的最基本解决方案,假设你没有任何要传递的参数,也不太关心构建原因等等。

def jen = Jenkins.instance;
def viewName = 'TECHNICAL';

def jobs = jen.getView(viewName).getJobNames()
jobs.each { job ->
   println "Running Job: " + job
   jen.getQueue().schedule(jen.getJob(job), 0, null, null)
}

根据需要在此基础上进行构建。可能需要识别不同类型的作业并相应地执行它们。

英文:

This is the bare minimal solution I can come up with, assuming you don't have any parameters to pass and you don't really care about the build cause, etc.

def jen = Jenkins.instance;
def viewName = 'TECHNICAL'

def jobs = jen.getView(viewName).getJobNames()
jobs.each { job -> 
   println "Running Job: " + job
   jen.getQueue().schedule(jen.getJob(job), 0, null, null)
}

Build on top of this as required. Probably you may have to identify different types of Jobs and execute them accordingly.

huangapple
  • 本文由 发表于 2023年3月9日 22:34:04
  • 转载请务必保留本文链接:https://go.coder-hub.com/75685996.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定