I think i've scoured every post on this topic but haven't found my specific scenario. (Maybe that means I'm building the wrong thing OR i've built something unique and new? The former is far more likely)
I have a multibranch pipeline in Jenkins being triggered by webhooks from GitHub. I want to automatically tag the repo being built only when a PR from develop|release|hotfix branches are closed and merged to master.
What I want to drill in on is how to identify when a master branch build is triggered by the merge from a PR, and not from anything else. I don't want to tag if master builds due to a non-PR merge. (This would allow updating readmes and code comments without generating a new tag.)
I'm getting the tag string from a file in the repo, and I know how to use the PR builder to identify the source and target of a pull request for when conditions. I know how to get the JSON build information and pull data out, but what I want doesn't seem to be there.
when { changeRequest target: 'master' } only identifies the PR build, not the master build that results when the PR is closed and merged.
when { branch 'master' } obviously identifies a master branch build, but how can I limit it to only build when the build is triggered the merge from a closed PR?
masterbuild that's happening is a result of a PR merge/closure, or just a regular ol' push to master (which is discouraged, but could happen - in which case I don't want to tag).I've tried to use
– Max Cascone Jun 16 '20 at 15:32currentBuild.getBuildCauses()but it only shows "push even to master", which i think applies to any merge to master. I'm only looking for PR merges.env.GITHUB_PR_STATEisCLOSEis not sufficient to detect that's it's a closed PR? – Argyle Jun 16 '20 at 17:16def build_cause = JSONArray.toList(currentBuild.getBuildCauses())What is the value ofbuild_cause._class[0]when the job is triggered from GitHub? – Argyle Jun 16 '20 at 17:20"actions": [ { "_class": "hudson.model.CauseAction", "causes": [ { "_class": "jenkins.branch.BranchEventCause", "shortDescription": "Pull request #27 updated" } ], but the branch build only has"actions": [ { "_class": "hudson.model.CauseAction", "causes": [ { "_class": "jenkins.branch.BranchEventCause", "shortDescription": "Push event to branch PLATDEV-6356-pipe-template-2" } ] },These are the same as shown at the very top of the build console output. – Max Cascone Jun 27 '20 at 04:17