如何使用 Job-DSL 触发构建

How to trigger build using Job-DSL

如何使用 Job-DSL 在 BitBucket 上完成推送后触发构建?

我认为是这样的,但是对于 BitBucket,不是 GitHub...

    triggers{
        githubPush()
    }

我也在寻找 "pull" 行为,Jenkins 每 N 分钟查看一次 BitBucket 上是否有新内容。

Bitbucket pullrequest builder plugin is currently not support by the Job DSL. Someone created a feature request 前一段时间,但据我所知,没有人在研究它。

但您可以使用 DSL configure block 为任何插件添加配置。

    triggers{
        scm("*/5 * * * *")
    }

对我来说很好。

我最终使用了 @daspilker 提到的 DSL 配置块。我还必须查看 Jenkins jog config.xml 以弄清楚如何编写 DSL。此代码对我有用。

job{
    configure { project ->
        project / 'triggers' << 'com.cloudbees.jenkins.plugins.BitBucketTrigger'{
            spec ''
        }
  }
}

https://jenkinsci.github.io/job-dsl-plugin/#method/javaposse.jobdsl.dsl.helpers.triggers.TriggerContext.bitbucketPush

job('example') {
    triggers {
        bitbucketPush()
    }
}