How do I prevent two pipeline jenkins jobs of the same type to run in parallel on the same node?

I do not want to allow two jobs of the same type (same repository) to run in parallel on the same node. How can I do this using groovy inside Jenkinsfile ?