컨트롤러 파이프 라인 작업의 입력 매개 변수에 따라 여러 파이프 라인 작업을 트리거하고 싶습니다.Jenkins Groovy 스크립트의 모든 파이프 라인 잡을 얻으십시오.
이 작업 내에서 나는 파이썬 스크립트에서 다시 주어진 목록에서 트리거하고 싶은 다른 파이프 라인의 이름을 빌드합니다.
node {
stage('Get_Clusters_to_Build') {
copyArtifacts filter: params.file_name_var_mapping, fingerprintArtifacts: true, projectName: 'UpdateConfig', selector: lastSuccessful()
script {
cmd_string = 'determine_ci_builds --jobname ' + env.JOB_NAME
clusters = bat(script: cmd_string, returnStdout: true)
output_array = clusters.split('\n')
cluster_array = output_array[2].split(',')
}
echo "${clusters}"
}
jobs = Hudson.instance.getAllItems(AbstractProject.class)
echo "$jobs"
def builders = [:]
for (i=0; i<cluster_array.size(); i++) {
def cluster = cluster_array[i]
def job_to_build = "BuildCI_${cluster}".trim()
echo "### branch${i}"
echo "### ${job_to_build}"
builders["${job_to_build}"] =
{
stage("${job_to_build}") {
build "${job_to_build}"
}
}
}
parallel builders
stage ("TriggerTests") {
echo "Done"
}
}
내 문제는,이 경우 수 있습니다이라고 내가 존재하지 않는 스테이지 Get_Clusters_to_Build
에서 얻을 이름과 작업의 커플. 그러므로 그들은 발동 될 수없고 나의 일은 실패합니다.
내 질문에, 모든 파이프 라인 작업의 이름을 얻는 방법이 있습니까? 빌드를 트리거 할 수 있는지 확인하기 위해 어떻게 사용할 수 있습니까?
나는이 시도를 jobs = Hudson.instance.getAllItems(AbstractProject.class)
에 의해 시도했지만 이것은 "정상적인"FreeStyleProject-Jobs 만 제공합니다.
나는 루프에서 이런 일을하고 싶지 :
def builders = [:]
for (i=0; i<cluster_array.size(); i++) {
def cluster = cluster_array[i]
def job_to_build = "BuildCI_${cluster}".trim()
echo "### branch${i}"
echo "### ${job_to_build}"
// This part I only want to be executed if job_to_build is found in the jobs list, somehow like:
if job_to_build in jobs: // I know, this is not proper groovy syntax
builders["${job_to_build}"] =
{
stage("${job_to_build}") {
build "${job_to_build}"
}
}
}
parallel builders
가능한 오류 블록을 'try/catch'로 묶어 오류 케이스를 처리 할 수 있습니다. 작업 유형은 ['org.jenkinsci.plugins.workflow.job.WorkflowJob'] (https://github.com/jenkinsci/workflow-job-plugin/blob/master/src/main/java/org/jenkinsci/)입니다. 플러그인/워크 플로우/작업/WorkflowJob.java). – mkobit
'job_to_build'의 이름을 알고 있다면 'Hudson.instance.getItemByFullName (job_to_build) '을 시도 했습니까? 그런 아이템이 없다면 null을 돌려 주어야합니다. 그래서 당신은 그 일을 정상적으로 건너 뛸 수 있습니다 ... – tom