The CHANGE_TARGET environment variable is contributed by the Multibranch Pipeline plugin, not this plugin. But this plugin does not appear to set the upstream "change" info correctly, so the target doesn't get set to the actual target, and can't be used with the built-in when conditions.
Following the link in my comment above, the built-in when block's changeRequest condition allows specifying optional attributes to further filter the change requests that will trigger a stage:
By adding a filter attribute with parameter to the change request, the stage can be made to run only on matching change requests. Possible attributes are id, target, branch, fork, url, title, author, authorDisplayName, and authorEmail. Each of these corresponds to a CHANGE_* environment variable, for example: when { changeRequest target: 'master' }.
Multibranch pipeline would normally allow something like:
stage {
when {
changeRequest(target: "master")
}
steps { . . }
}
which would allow the stage to run only if it is a change request (i.e., an unmerged open code review in Gerrit), AND it is targeting the master branch.
From the issue description, you can see that the two fields are set, but appear to be swapped. So for a change targeting the master branch, it seems like this would work:
when {
changeRequest(branch: "master")
}
But that isn't the right definition of "branch" and "master" in terms of Multibranch Pipeline change requests.
In Multibranch Pipeline terms, "branch" would be the source of the change – for example, in a Github PR, it would be the forked PR branch name; and "target" would be the branch into which the change WILL merge, if it is approved and submitted. Usually that target would be "master" or "dev", for example, while branch would be some other fork branch ("fork:pr-fix-a-thing").
In Gerrit terms, the equivalent definitions would be: "branch" is the refs/changes/* ref or the ##/#####/# pseudo-branch-name we are currently using in this plugin. While "target" should be the change's target branch (where it will merge when it's approved and submitted).
There are other useful conditions that could be checked with the when.changeRequest conditions, as documented here: https://www.jenkins.io/doc/book/pipeline/syntax/#when. Some of those work correctly, but it seems like branch and target might be swapped, perhaps?