我有一个jenkins作业(A),它创建并推送一个新的git分支,模式为releases/major.minor。我有一个jenkins多分支管道(B),它为所有名为releases/*的分支构建。在A完成后,我想立即在新创建的分支上触发B,但jenkins不会运行B/major.minor,直到有一个新的扫描。如何触发扫描?
A
releases/major.minor
B
releases/*
B/major.minor
rkue9o1l1#
您可以使用build step扫描多分支项目。
build
build( job: '/my-multibranch-project-name', wait: false, )
您必须包含wait: false,否则将出现以下错误:
wait: false
ERROR: Waiting for non-job items is not supported
不幸的是,这意味着如果要在关联的分支上运行多分支管道,则需要手动检查该作业是否存在。
def ensureMultibranchJobExists(Map args) { def branch = args['branch']?.replaceAll('/', '%252F') def rootJob = args['rootJob'] if (branch == null) { throw new NullPointerException('branch is required') } if (rootJob == null) { throw new NullPointerException('rootJob is required') } // env.JENKINS_URL ends with a slash. env.ENSURE_MULTIBRANCH_JOB_EXISTS_URL = "${env.JENKINS_URL}job/$rootJob/job/$branch/" print "Ensuring multibranch job exists: ${env.ENSURE_MULTIBRANCH_JOB_EXISTS_URL}" def lastHttpStatusCode = null for (int i=0; i < 12; i++) { lastHttpStatusCode = sh( returnStdout: true, script: ''' #!/bin/bash set -euo pipefail curl \ --output /dev/null \ --silent \ --user devtools:<MY_TOKEN> \ --write-out '%{http_code}' \ "${ENSURE_MULTIBRANCH_JOB_EXISTS_URL}" \ ; '''.trim(), ) if (lastHttpStatusCode == '200') { break } else { print "Last status code: $lastHttpStatusCode" } sleep( time: 10, unit: 'SECONDS', ) } if (lastHttpStatusCode != '200') { error "${env.ENSURE_MULTIBRANCH_JOB_EXISTS_URL} failed. Expected 200 status code, but received: $lastHttpStatusCode" } }
1条答案
按热度按时间rkue9o1l1#
您可以使用
build
step扫描多分支项目。您必须包含
wait: false
,否则将出现以下错误:不幸的是,这意味着如果要在关联的分支上运行多分支管道,则需要手动检查该作业是否存在。