英文:
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论