Trying to cancel a running pipeline once a new job instance is triggered.
Found Here that setResult('FAILURE') might do the trick.
But seems not possible as generated the error:
java.lang.SecurityException: can only set the result property on the current build
Here is a snipped I am using:
    stage('Cancel running job') {
        steps {
                script {
                    def buildToCancel 
                    buildToCancel = currentBuild.getPreviousBuildInProgress()
                    buildToCancel.setResult('FAILURE') 
                }
        }
    }
And yet, cancelling a job from Jenkins UI is possible, so question is how to make it done from a jenkinsfile.