如何捕捉詹金斯身材的成因?由GitLab触发

时间:2019-03-26 15:20:05

标签: java jenkins groovy hudson jenkins-groovy

在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如何读取生成原因?

1 个答案:

答案 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