Cancel queued builds and aborting executing builds using Groovy for Jenkins

前端 未结 9 2142
礼貌的吻别
礼貌的吻别 2020-12-01 00:28

For Jenkins using a Groovy System Script, is there a way to easily search the build queue and list of executing builds for some criteria (specifically a parameter that match

9条回答
  •  再見小時候
    2020-12-01 01:15

    I haven't tested it myself, but looking at the API it should be possible in the following way:

    import hudson.model.*
    import jenkins.model.Jenkins
    
    def q = Jenkins.instance.queue
    
    q.items.findAll { it.task.name.startsWith('my') }.each { q.cancel(it.task) }
    

    Relevant API links:

    • http://javadoc.jenkins-ci.org/jenkins/model/Jenkins.html
    • http://javadoc.jenkins-ci.org/hudson/model/Queue.html

提交回复
热议问题