在Jenkins文件(常规语法)中,使用hudson.model.Cause$UserIdCause
中的currentBuild.getBuildCauses('hudson.model.Cause$UserIdCause')
捕获了手动生成操作(如果有)的原因
在Jenkins CI code中,hudson.triggers.SCMTrigger.SCMTriggerCause
看起来已被弃用。
@Deprecated
public SCMTrigger(String scmpoll_spec, boolean ignorePostCommitHooks) throws ANTLRException {
super(scmpoll_spec);
this.ignorePostCommitHooks = ignorePostCommitHooks;
}
在来自GitLab的推送事件或合并事件中,Jenkinsfile如何读取生成原因?
最佳答案
如果要在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