首页 > 解决方案 > 在 jenkinsfile 中使用脚本语法时不会触发多分支作业

问题描述

我有一个多分支管道,其中包含两个分支(产品仓库的分支)master 和 qac。

两个分支(即 master 和 qac)都有 jenkinsfile。

在 jenkinsfile 中使用声明性语法时,作业会在 git push 上触发。

下面是声明性的 Jenkinsfile

library(
  identifier: 'jenkins-library@master',
  retriever: modernSCM(
    [
      $class: 'GitSCMSource',
      remote: 'https://github.com/ABC/Jenkins-CommonLib.git',
      credentialsId: '2023203e3-a0da-445c-ab1c-1d26a416e3f8'
    ]
  )
)
properties([pipelineTriggers([githubPush()])])
pipeline {
  agent any
  stages {

    stage('Stage 1') {
      steps {
        script {
          echo 'Stage 1'
        }
      }
    }
}
}

但是,当使用脚本化的 jenkinsfile 时,作业不会在 git push 上触发,但 jenkins 会收到 Push 事件(在 jenkins 日志中找到)

下面是脚本化的詹金斯文件

library(
identifier: 'jenkins-library@master',
retriever: modernSCM(
[
$class: 'GitSCMSource',
remote: 'https://github.com/ABC/Jenkins-CommonLib.git',
credentialsId: '20860d33-a0da-445c-ab1c-1d26a416e3f8'
]
)
)
properties([pipelineTriggers([githubPush()])])
node {
serviceAppBuild{}
}

ServiceAppBuild 是共享库中的一个 groovy 文件,它实际上包含管道阶段。

如何使用脚本 jenkinsfile 触发构建?

标签: jenkinsmultibranch-pipeline

解决方案


推荐阅读