In Jenkins file(groovy syntax), manual build action(if any) cause is grabbed using hudson.model.Cause$UserIdCause in currentBuild.getBuildCauses('hudson.model.Cause$UserIdCause')
hudson.triggers.SCMTrigger.SCMTriggerCause looks deprecated in Jenkins CI code.
@Deprecated
public SCMTrigger(String scmpoll_spec, boolean ignorePostCommitHooks) throws ANTLRException {
super(scmpoll_spec);
this.ignorePostCommitHooks = ignorePostCommitHooks;
}
On push event or merge event from GitLab, How do Jenkinsfile read the build cause?
If you're looking to execute a stage on a Gitlab trigger:
stage('stage') {
when {
triggeredBy "GitLabWebHookCause"
}
}
To get the data of the Gitlab cause you have the following syntax:
currentBuild.rawBuild.getCause(com.dabsquared.gitlabjenkins.cause.GitLabWebHookCause).getData()
Example: get last commit
commit = currentBuild.rawBuild.getCause(com.dabsquared.gitlabjenkins.cause.GitLabWebHookCause).getData().getLastCommit()
Documentation of the GitlabWebHookCause: https://javadoc.jenkins.io/plugin/gitlab-plugin/com/dabsquared/gitlabjenkins/cause/GitLabWebHookCause.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With