Getting build cause

66 views
Skip to first unread message

Shade Alabsa

unread,
Jul 27, 2016, 11:10:34 PM7/27/16
to Jenkins Users
I've been trying to write a Jenkinsfile to do different tasks based on whether it's a PR or a merge in Jenkins 2. I've found the snippet below which will tell me if the build was triggered by a user or via Github. The problem is that if the build was started via a PR or a merge the reason is the same. Is there a better way to get this? Thanks!

 def causes = currentBuild.rawBuild.getCauses()

    for ( cause in causes) {
        echo "Cause: " + cause.getShortDescription()
    }

Jesse Glick

unread,
Aug 4, 2016, 11:12:00 AM8/4/16
to Jenkins Users
On Wednesday, July 27, 2016 at 11:10:34 PM UTC-4, Shade Alabsa wrote:
I've been trying to write a Jenkinsfile to do different tasks based on whether it's a PR or a merge in Jenkins 2. I've found the snippet below which will tell me if the build was triggered by a user or via Github.

Not sure exactly what your situation is, but if you are using GitHub organization folders (or single multibranch projects), you should be able to just check `env.CHANGE_ID != null` to detect a PR build.
Reply all
Reply to author
Forward
0 new messages