我正在考虑在 Jenkins 中为我的构建工作使用 Groovy 脚本,因为我有一些条件可以检查可能需要访问 Jenkins API。
是否可以通过 Groovy 脚本找出是谁或什么触发了构建?SCM 更改、另一个项目或用户。我刚刚开始阅读一些关于 Groovy 和 Jenkins API 的内容。
我想检查以下条件并相应地构建。一些伪代码:
def buildTrigger JenkinsAPI.thisBuild.Trigger
if (buildTrigger == scm) {
execute build_with_automake
def new_version = check_git_and_look_up_tag_for_version
if (new_version) {
execute git tag new_release_candidate
publish release_candidate
}
} else if (buildTrigger == "Build other projects") {
execute build_with_automake
}
该项目应该建立在每个 SCM 更改的基础上,但只有在版本增加时才标记和发布。当另一个项目触发构建时,它也应该构建。