Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/git/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/jenkins/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Git 如何触发对jenkins多分支管道的扫描?_Git_Jenkins - Fatal编程技术网

Git 如何触发对jenkins多分支管道的扫描?

Git 如何触发对jenkins多分支管道的扫描?,git,jenkins,Git,Jenkins,我有一个jenkins作业(a),它创建并推送一个新的git分支,模式为releases/major.minor。我有jenkins多分支管道(B),它为所有名为releases/*的分支构建。在A完成后,我想立即在新创建的分支上触发B,但jenkins不会运行B/major.minor,直到有新的扫描 如何触发扫描?您可以使用来扫描多分支项目。但是,您必须包括wait:false,否则将出现以下错误: ERROR: Waiting for non-job items is not suppor

我有一个jenkins作业(
a
),它创建并推送一个新的git分支,模式为
releases/major.minor
。我有jenkins多分支管道(
B
),它为所有名为
releases/*
的分支构建。在
A
完成后,我想立即在新创建的分支上触发
B
,但jenkins不会运行
B/major.minor
,直到有新的扫描


如何触发扫描?

您可以使用来扫描多分支项目。但是,您必须包括
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"
  }
}
def ensureMultibranchJobExists(映射参数){
def branch=args['branch']?.replaceAll('/','%252F'))
def rootJob=args['rootJob']
if(分支==null){
抛出新的NullPointerException('需要分支')
}
if(rootJob==null){
抛出新的NullPointerException('rootJob是必需的')
}
//env.JENKINS_URL以斜杠结尾。
env.sure_MULTIBRANCH_JOB_存在_URL=“${env.JENKINS_URL}JOB/$rootJob/JOB/$branch/”
打印“确保多分支作业存在:${env.Survey_multibranch_job_exists_URL}”
def lastHttpStatusCode=null
对于(int i=0;i<12;i++){
lastHttpStatusCode=sh(
是的,
脚本:“”
#!/bin/bash
设置-euo管道故障
卷曲\
--输出/dev/null\
--沉默的\
--用户开发工具:\
--写出“{http_code}”\
“${确保多分支作业存在\u URL}”\
;
''.trim(),
)
如果(lastHttpStatusCode==“200”){
打破
}否则{
打印“最后状态代码:$lastHttpStatusCode”
}
睡眠(
时间:10,,
单位:秒,
)
}
如果(lastHttpStatusCode!=“200”){
错误“${env.sure_MULTIBRANCH_JOB_EXISTS_URL}失败。预期状态代码为200,但收到:$lastHttpStatusCode”
}
}