728x90
Jenkins 에서 실행 중인 빌드나 큐에 대기 중인 빌드를 Script Console에서 일괄적으로 중단하는 방법
Script Console : http://{JENKINS_URL}/manage/script
import java.util.ArrayList
import hudson.model.*;
import jenkins.model.Jenkins
// 1. Remove everything which is currently queued
def q = Jenkins.instance.queue
for (queued in Jenkins.instance.queue.items) {
q.cancel(queued.task)
}
// 2. stop all the currently running jobs
// 2번만 실행해도 큐에 쌓인 빌드까지 중단됨
for (job in Jenkins.instance.items) {
stopJobs(job)
}
def stopJobs(job) {
if (job in com.cloudbees.hudson.plugins.folder.Folder) {
for (child in job.items) {
stopJobs(child)
}
} else if (job in org.jenkinsci.plugins.workflow.multibranch.WorkflowMultiBranchProject) {
for (child in job.items) {
stopJobs(child)
}
} else if (job in org.jenkinsci.plugins.workflow.job.WorkflowJob) {
if (job.isBuilding()) {
for (build in job.builds) {
build.doKill()
}
}
}
}
+ queue에 쌓인 빌드 삭제 조건문 추가
import java.util.ArrayList
import hudson.model.*;
import jenkins.model.Jenkins
// 1. Remove everything which is currently queued
def q = Jenkins.instance.queue
for (queued in Jenkins.instance.queue.items) {
if (queued.task['runId'].contains('멈추고싶은JOB이름') ) {
q.cancel(queued.task)
}
else { // skip
println(queued.task)
}
}
# Ex) println(queued.task)
ExecutorStepExecution.PlaceholderTask{runId=CI_MAIN_JOB#79060,label=master,context=CpsStepContext[16:node]:Owner[CI_MAIN_JOB/79060:CI_MAIN_JOB #79060],cookie=null,auth=null}
+ Jenkins Log 참고
# doKill() 했을때 Jenkins Log
Hard kill!
Finished: ABORTED
# doStop() 했을때 Jenkins Log
Aborted by USER
[Pipeline] }
[Pipeline] // stage
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
org.jenkinsci.plugins.workflow.actions.ErrorAction$ErrorId: a0bff3b3-17e8-48dc-9f85-931
Finished: ABORTED
728x90
'Jenkins' 카테고리의 다른 글
[Script Console] 실행 중인 job의 파라미터 가져오기 (0) | 2024.01.17 |
---|---|
Jenkins에서 json 파싱하는 법 (1) | 2023.12.27 |
Jenkins 빌드 로그를 변수에 저장하기 (0) | 2023.08.08 |
Jenkins idle node 조회 (0) | 2023.06.20 |
Jenkins Gerrit 서버 등록 에러 (id_rsa is not a valid key file) (0) | 2023.06.13 |