在Jenkins文件(常规语法)中,使用hudson.model.Cause$UserIdCause
中的currentBuild.getBuildCauses('hudson.model.Cause$UserIdCause')
捕获了手动构建操作(如果有)的原因
hudson.triggers.SCMTrigger.SCMTriggerCause
在Jenkins CI code中似乎已弃用。
@Deprecated
public SCMTrigger(String scmpoll_spec, boolean ignorePostCommitHooks) throws ANTLRException {
super(scmpoll_spec);
this.ignorePostCommitHooks = ignorePostCommitHooks;
}
在GitLab的推送事件或合并事件中,Jenkinsfile如何读取生成原因?
答案 0 :(得分:0)
如果要在Gitlab触发器上执行阶段:
stage('stage) {
when {
triggeredBy "GitLabWebHookCause"
}
}
要获取Gitlab的数据,请使用以下语法:
currentBuild.rawBuild.getCause(com.dabsquared.gitlabjenkins.cause.GitLabWebHookCause).getData()
示例:获取最后一次提交
commit = currentBuild.rawBuild.getCause(com.dabsquared.gitlabjenkins.cause.GitLabWebHookCause).getData().getLastCommit()
GitlabWebHook的文档原因: https://javadoc.jenkins.io/plugin/gitlab-plugin/com/dabsquared/gitlabjenkins/cause/GitLabWebHookCause.html